JavaScript equality operator

Understand the basics of JavaScript equality operators

These operators accept two values and return a Boolean value:

  • ==Check for equality
  • !=Check for inequality
  • ===Check strict equality
  • !==Check for strict inequality

Let's talk about what we meanstrict. If there is no strict check, the second operand will be converted to the type of the first operand before the comparison is performed. Strictly prevent this situation.


const a = true

a == true //true a === true //true 1 == 1 //true 1 == β€˜1’ //true 1 === 1 //true 1 === β€˜1’ //false

You cannot check whether objects are equal: two objects are never equal to each other. The only case where the check may be true is if the two variables refer to the same object.

Some features that need to be noted:NaNAlways withNaN.

NaN == NaN //false

nullwithundefinedIf compared in non-strict mode, the values are equal:

null == undefined //true
null === undefined //false

Download mine for freeJavaScript beginner's manual

More js tutorials: