= 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; // assigns 25 to age let name = "Alice"; // assigns "Alice" to name
⚠️ 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 // true → "5" converted to number 5 false == 0 // true → false converted to 0 null == undefined // true → both represent “no value”

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 // false → string vs number 5 === 5 // true → same type, same value false === 0 // false → boolean vs number
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