Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Inequality operator (!=)

The != operator tests inequality using comparison rules that allow implicit type conversion. It negates ==, so values of different types do not necessarily produce true. The !== operator does not perform these conversions.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

left != right

left != right returns true when the operands are unequal under the rules of ==, and false otherwise. It is equivalent to !(left == right). This is an ECMAScript language operator, not a browser API.

With different types, comparison may apply conversion: 5 != "5" and 0 != false produce false. The pair null and undefined is treated as equal, so null != undefined also produces false. This does not mean both sides are always converted to numbers.

For operands of the same type, strict equality rules apply and the result is negated. NaN != NaN produces true, while 0 != -0 produces false. Objects are compared by identity, not contents: two separate {} instances are unequal, but an object compared with itself is not unequal.

Use !== when you do not want implicit conversions: 5 !== "5" produces true. When comparing an object with a primitive value, != may invoke object-to-primitive conversion; that code can have side effects or throw an exception. The operator therefore does not necessarily complete with a Boolean result.

Examples

console.log(5 != "5");
console.log(5 !== "5");
console.log(0 != false);
console.log(null != undefined);
console.log(NaN != NaN);
const item = {};
console.log(item != item);
console.log(item != {});

Result

false
true
false
false
true
false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources