Created
February 7, 2011 23:50
-
-
Save founddrama/815552 to your computer and use it in GitHub Desktop.
You may encounter some strange things when comparing single-item Arrays with other things in JavaScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] == [1]; | |
// false | |
[1] == 1; | |
// true | |
[1] === 1; | |
// false | |
[1] == '1'; | |
// true | |
[1, 1] == 1; | |
// false (of course?) | |
[1, 1] == '1,1'; | |
// true | |
// and then it gets weird: | |
[true] == true; | |
// false; but compare with: | |
true == true; | |
// true (sanity check...) | |
[true] == 'true'; | |
// true (there's that valueOf/toString again) | |
// now... | |
[1] == true; | |
// true | |
['1'] == true; | |
// true | |
[''] == false; | |
// true | |
[0] == false; | |
// true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@see
http://notundefined.tumblr.com/post/3208290434/the-pleasures-and-perils-of-javascripts-promiscuous