JavaScript:StrictEquality
lastmod 2026-02-26created 2021-07-202 edits
Equal to(==) vs Strict equal(===)
- MDN: Equality comparisons and sameness
- Stackoverflow: Does it matter which equals operator (== vs ===) I use in JavaScript comparisons?
- Difference between JavaScript == (equality, equal to) and === (identity, strictly equal to)
Equal to (==):
- When both operands are the same type, true if the values are equal
- When the operands are different types, true if the two operands become equal under predefined type conversion rules
Strict equal (===):
- Checks whether the two operands are equal without type conversion.
- True if the operands are primitive types and the values are equal
- True if the operands are object types and refer to the same object
- False if the objects have different addresses, even if their structure and contents are the same
Comparison table:
| x | y | == | === |
| undefined | undefined | true | true |
| null | null | true | true |
| true | true | true | true |
| false | false | true | true |
| 'foo' | 'foo' | true | true |
| 0 | 0 | true | true |
| +0 | -0 | true | true |
| +0 | 0 | true | true |
| -0 | 0 | true | true |
| 0 | false | true | false |
| "" | false | true | false |
| "" | 0 | true | false |
| '0' | 0 | true | false |
| '17' | 17 | true | false |
| [1,2] | '1,2' | true | false |
| new String('foo') | 'foo' | true | false |
| null | undefined | true | false |