WTFJS

March 2, 2010

OK, this is completely wonderful — exactly a thing I would have wanted to make, except somebody else made it for me, better. Keep this in mind in case anyone ever tells you the old yarn about how JavaScript is only a terrible language because of browser inconsistencies..

An example:

// 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?

Comments are closed.