Jasyn Marais

What's the difference between "==" and "==="?

16 February 2023

In JavaScript, the double equals (==) and triple equals (===) operators are used for comparison.

The == operator compares the value of two operands, and returns true if they are equal, regardless of their data types. For example:

console.log(5 == "5"); // true
console.log(true == 1); // true
console.log(null == undefined); // true

On the other hand, the === operator compares both the value and data type of two operands, and only returns true if they are strictly equal. For example:

console.log(5 === "5"); // false
console.log(true === 1); // false
console.log(null === undefined); // false

It is generally recommended to use the === operator when comparing values in JavaScript, as it avoids unexpected type coercion and produces more predictable results. However, there are some cases where the double equals operator may be useful, such as when checking for null or undefined values.

Summary