# Check if two Numbers are NOT equal in JavaScript

Borislav Hadzhiev

Mon Oct 18 20212 min read

## Check if two Numbers are NOT equal#

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
```Copied!```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
```Copied!```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.

## Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Copyright ยฉ 2021 Borislav Hadzhiev