Advertisement
Advertisement


Difference between == and === in JavaScript


Question

What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators?

2019/11/09
1
1636
11/9/2019 2:31:09 PM

Accepted Answer

=== and !== are strict comparison operators:

JavaScript has both strict and type-converting equality comparison. For strict equality the objects being compared must have the same type and:

  • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
  • Two Boolean operands are strictly equal if both are true or both are false.
  • Two objects are strictly equal if they refer to the same Object.
  • Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]

Comparison Operators - MDC

2018/08/29
1187
8/29/2018 12:58:29 AM


Source: https://stackoverflow.com/questions/523643
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]