Skip to main content

Bizarre Javascript

Operaters "+" and "-" have different behaviour

var x =50- 0; // x == 50
var x =50+ 0; // x == “500”

A==B and A==C, but B!=C

0 == ''; // true -> A==B
0 =='0'; // true -> A==C
'' == '0'; //false -> B!=C

Null hustle

 null == 0; // false null- object
null > 0; // false null- NaN
null >= 0; //true

Transitive law violation

Transitive law declare that if a is equal to b and b is equal to c, then a is equal to c. Which might not work in some cases in JavaScript.

Never use new String constructor
var a = new String("foo");
var b = "foo";
var c = new String("foo");

a == b; // true
b == c; // true
a == c; // false