What is the difference between the equality operators == and ===?

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

Equality operators:
The equality operator converts the operands if they are not of the same type, then applies strict comparison. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

Syntax:
x == y

Examples:

1    ==  1         // true
1    == '1'        // true
'1'  ==  1         // true
0    == false      // true
0    == null       // false
var object1 = {'key': 'value'}, object2 = {'key': 'value'}; 
object1 == object2 //false
0    == undefined  // false
null == undefined  // true

Strict equality (===)
Triple equals (===) checks for strict equality, which means both the type and value must be the same.

Syntax:
x == y

1 === 1   // true
1 === '1' // false
var object1 = {'key': 'value'}, object2 = {'key': 'value'};
object1 === object2 //false
0
JavaScript 3 years 0 Answer 438 views 0

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>