Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Strict equality (===)

Compares values without type conversion.

Available since: ES3

Syntax

a === b / a !== b

Examples

Strict and loose comparison:

console.log(5 === 5);
console.log(5 === '5');
console.log(5 == '5');

Output:

true
false
true

Oddities of loose comparison:

console.log(0 == '');
console.log(null == undefined);
console.log(null === undefined);

Output:

true
true
false

Objects are compared by reference:

const a = { x: 1 };
const b = { x: 1 };
 
console.log(a === b);
console.log(a === a);

Output:

false
true

Notes

Always use === and !==. Loose == converts types by confusing rules first. The only common exception is value == null, which checks for both null and undefined.

See also

  • Object.is — Compares two values almost like === but handles NaN and -0 correctly.
  • typeof — Returns a string with the type of a value.
  • Number.isNaN — Checks that a value is NaN, without type conversion.

In the tutorial

  • Comparison — Comparison operators in JavaScript — greater, less, strict and loose equality, comparing strings and NaN.

Thanks for reading!

Donate to the site — we work hard for you.