= vs == vs === in JavaScript
JavaScript has three different operators that use the equals sign:
=, ==, and ===.
They look similar but perform very different functions.
1. = The Assignment Operator
Used to assign a value to a variable.
It does not compare anything — it simply stores a value.
let age = 25;
let name = "Alice";
⚠️ Using = inside a conditional statement instead of == or === is a common programming error.
2. == The Loose Equality Operator
Compares values after type conversion (coercion).
If the types differ, JavaScript tries to convert one value to match the other.
"5" == 5
false == 0
null == undefined
Because coercion is automatic, == can produce surprising results.
3. === The Strict Equality Operator
Compares values without type conversion.
Both the value and its type must be identical for === to return true.
"5" === 5
5 === 5
false === 0
Best practice: always use === (and !==) for equality checks.
Interactive Demo
Compare any two values using == and ===:
Summary Table
| Operator |
Purpose |
Type Conversion? |
Example |
Result |
= |
Assignment |
No |
x = 10 |
Stores 10 in x |
== |
Loose Equality |
Yes |
"5" == 5 |
true |
=== |
Strict Equality |
No |
"5" === 5 |
false |