How === works ?
Suppose the following expression
1 | A === B |
How strict equality works in JavaScript? Here are the steps:
- If the operands are of different types, return
false
- If both operands are objects, return true only if they refer to the same object.
- If both operands are null or both operands are undefined. return true.
- If either operand is
NaN
, return false - Otherwise, compare the two operand’s value as below
- Numbers must have the same numeric values.
- Strings must have the same characters in the same order.
- Booleans must be both true or both false.
Code Example
1 | console.log(1 === '1'); // false, different type. |
References
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality