JavaScript != Inequality Operator
The loose inequality operator (!=) checks whether two values are not equal, converting types first. !== is usually preferred.
Description
The inequality operator != returns true if the operands are not equal after type conversion. It's the negation of == and has the same surprises, so !== is normally the better choice.
It converts types using the same rules as ==: strings and booleans become numbers, objects become primitives, and null and undefined are equal only to each other. That means '0' != false is false, which surprises many people.
The one common, deliberate use is value != null, which is true for anything except null and undefined in a single check. Elsewhere, prefer !==, which compares without converting types.
Properties
- Operator
!=- Category
- Comparison
- Precedence
- 8 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x != yExample
Browser Support
The following information will show you the current browser support for the != operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





