In JavaScript, the double and triple equals are used for comparison between two operands. The difference between both the equals is:
Sr. No. | Key | Double Equals (==) | Triple Equals (===) |
---|---|---|---|
1 | Naming | Double equals named as Equality Operator. | Triple equals named as Identity / Strict equality Operator. |
2 | Comparison | Double equals used as Type converting the conversion | Triple equals used as Strict conversion without performing any conversion in operands. |
3 | Syntax | Double equals has syntax for comparison as (a == b) | Triple equals has syntax for comparison as (a === b) |
4 | Implementation | Double equals first convert the operands into the same type and then compare i.e comparison would perform once both the operands are of the same type. This is also known as type coercion comparison. | On the other hand, triple equals do not perform any type of conversion before comparison and return true only if type and value of both operands are exactly the same. |
Example of == vs ===
Equals.jsp
var a = true; var b = 1; var c = true; console.log (a == b); // first convert 1 into boolean true then compare console.log (a === c); // both are of same type no conversion required simple compare. console.log (a === b); // no conversion performed and type of both operands are not of same type so expected result is false.
Output
true true false