Introduction
Let’s look at a few equality tests:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18console.log(true==1); // true
console.log(1=="1"); // true
console.log(true===1); // false
console.log(1==="1"); // false
var a = [1,2,3];
var b = [1,2,3];
var c = a;
console.log(a==b); // false
console.log(a==c); // true
var d = new String("text");
var e = "text";
console.log(d==e); // true
console.log(d===e); // false
If you understand why the equality comparison operators return what they return above, then turn around and never look back :D. If not then continue reading…