Javascript's Nearly Unforgiveable Sins

Logic

Implicit conversion with ==

0=="0"

But no unboxing with ===

0!==new Number(0)

Equality is not transitive

"" == 0 
0 == "0" 
"" != "0"

parseInt is not base ten!

parseInt("8"); //8
parseInt("08"); //0

Types and Objects don’t know about eachother

typeof "hello" === "string"; //true
typeof new String("hello") === "string"; //false
"hello" instanceof String; //false
new String("hello") instanceof String; //true

No Actual Map

People use object literals {} to construct map-like objects, but they’re not real maps! What they actually do is map the string conversion of the object. Look what happens when you try to nest objects inside objects:

> var a = {x:"a"}
undefined
> var b = {x:"b"}
undefined
> var obj = {}
undefined
> obj[a] = "a"
"a"
> obj[b] = "b"
"b"
> obj[a]
"b"

Comments