Check if two Numbers are NOT equal in JavaScript

Borislav Hadzhiev

Last updated: Oct 18, 2021

Check out my new book

**Use the strict inequality (!==) operator to check if two numbers are not equal
to one another, e.g. a !== b. The strict inequality operator returns true if
the numbers are not equal and false otherwise.**

index.js

`const a = 5; const b = 10; if (a !== b) { console.log('✅ numbers are NOT equal'); } else { console.log('⛔️ numbers are equal'); }`

We used the
strict inequality (!==)
operator to check if the numbers `5`

and `10`

are not equal to one another.

The operator returns a boolean result:

`true`

if the values are not equal`false`

if the values are equal

The strict inequality (!==) operator is the negation of the strict equality (===) operator.

Here are some more examples.

index.js

`console.log(3 !== 3); // 👉️ false console.log(3 !== '3'); // 👉️ true console.log(3 !== 5); // 👉️ true console.log(null !== null); // 👉️ false console.log(undefined !== undefined); // 👉️ false console.log(NaN !== NaN); // 👉️ true`

The strict inequality (!==) operator considers two values of different types to be different, as opposed to the loose inequality (!=) operator.

**This means that two values of different types will never be equal, when using
the strict inequality operator.**

It's always recommended to use the strict operators (!==, ===) because they don't try to coerce the values to the same type before comparing them and return more intuitive and easier to read results.

Notice that in the last example, the evaluation `NaN !== NaN`

returns `true`

.
This is because `NaN`

(not a number) is the only value in JavaScript, which is
not equal to itself.

Use the search field on my Home Page to filter through my more than 3,000 articles.