Use === Instead of ==

Learn the difference between the === and == operators.

Many JavaScript programmers often repeat the mistake of comparing using ==, which is the type-coercion non-strict equality operator.

Example of == operator

Let’s look at an example that shows why using == may be a bad idea.

Press + to interact
const a = '1';
const b = 1;
const c = '1.0';
console.log(a == b);
console.log(b == c);
console.log(a == c);

Explanation

In the short piece of code given above, the constants a, b, and c have the values ‘1’, 1, and ‘1.0’, respectively. One value is of number type, and the other two are of string type. The last three lines of code ...

Access this course and 1400+ top-rated courses and projects.