== vs ===

Difference

== (equality operator) and === (strict equality operator) are the operators to compare two operands.
The == operator does type conversions before comparing the values. On the other hand, the === operator doesn't perform any type conversions.
It means that the === operator returns true if two operands have the same type and same value.
For example:
// `true` is converted to 1 and then compared to 1
true == 1;      // true
true === 1;     // false
The following table demonstrates the result of these operators:
The result is true
The result is false
0
1
true
false
+0
-0
"true"
"false"
"1"
"0"
""
null
undefined
Infinity
-Infinity
[]
{}
[1]
[0]
0
1
true
false
+0
-0
"true"
"false"
"1"
"0"
""
null
undefined
Infinity
-Infinity
[]
{}
[1]
[0]

Good practice

Always use === to compare values.
Hit the Subscribe button for the latest news on my tools. No spam. Ever!
© 2020 Nguyen Huu Phuoc. All rights reserved