Double equals vs Triple equals in JavaScript

Difference between == and === or double equal vs triple equal operators in JavaScript,
JavaScript has both strict and type-converting equality comparison Operators.

 == equality operator will attempt to resolve the data types via type coercion before making a comparison. === equality operator (Strict equality) will return false if the types are different.

Double equal (==) in JavaScript

0 == false        // true
1 == true         // true
1 == "1"          // true, auto type coercion 
null == undefined // true, auto type coercion  


While === (triple equal) is Strict Equality Operator, triple equal operator strictly check the data type for matching the value.

Triple equal (===) in JavaScript

0 === false        // false, because they are of a different type
1 === true         // false, because they are of a different type
1 === "1"          // false, because they are of a different type
1 === 1            // true,  because they are of a similar type
null == undefined  // false, because they are of a different type



Popular Posts