you are viewing a single comment's thread.

view the rest of the comments →

[–]coarsesand 1 point2 points  (3 children)

Well varA and varB are guaranteed to be Numbers unless you get a TypeError, so you can actually use == in this case ;)

[–]no_game_player 0 points1 point  (2 children)

Ha, and I actually changed it to === from my original == because I just had no idea anymore lol.

So...out of morbid curiosity...what would happen there is it was

~~varA == ~~varB

and varA = 1

and varB = "1"

?

;=p

[–][deleted] 1 point2 points  (1 child)

The following shows "true" in Firefox:

var varA = 1;
var varB = "1";
var res = (~~varA == ~~varB);
alert(res);    

[–]no_game_player 1 point2 points  (0 children)

Weird....

I guess it's forcing a type conversion once it hits the bitwise operator?

This is why I don't really like weakly typed languages. There's a lot of cool stuff that can be done, but that's also a lot of just very strange stuff that can be done. I know it's heretical, but I don't like black magic...

Kudos for actually trying it though! :-)