Created
February 26, 2010 20:46
-
-
Save getify/316141 to your computer and use it in GitHub Desktop.
This file contains 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
// be careful with those implicit .toString() calls in == comparison | |
typeof "abc" == "string" // true | |
typeof String("abc") == "string" // true | |
String("abc") == "abc" // true -- same types get casted to equal each other | |
String("abc") instanceof String // false -- hmmm... | |
(new String("abc")) instanceof String // true | |
String("abc") == (new String("abc")) // true -- wait, wtf? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
String("abc") == "abc" // true -- same types get casted to equal each other
That's not casting.
As you can see further down
String("abc")
doesn't return an object that's an instance ofString
. You'd obviously need to donew String("abc")
for that.Without
new
,String("abc")
simply returns astring
, not an instance ofString
. That's whyString(5) === '5'