Which equals operator (== vs ===) should be used in JavaScript?



Double equals (==) is abstract equality comparison operator, which transforms the operands to the same type before making the comparison. 

For example,

5 ==  5       //true '5' == 5      //true 5 == '5'      //true 0 == false    //true

Triple equals (===) are strict equality comparison operator, which returns false for different types and different content.

For example,

5 === 5  // true 5 === '5' // false var v1 = {'value':'key'}; var v2 = {'value': 'key'}; v1 === v2 //false
Updated on: 2020-01-07T10:59:49+05:30

172 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements