Friday 18 November 2011

Double equals vs Triple equals Operators in JavaScript

 

Double equals vs Triple equals Operators in JavaScript

 
 
Related Queries.
1)Difference between == and === in JavaScript

2)double equal vs triple equal operators in JavaScript


JavaScript has both strict and type-converting equality comparison Operators.

As we know == (double equal) is a Type Converted Equality Operator it convert data type accordingly.

Example:-
 
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.

Example:-
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

No comments:

Post a Comment