JavaScript == Equality Operator
The loose equality operator (==) checks whether two values are equal after converting them to a common type. The strict === operator is usually preferred.
Description
The equality operator == compares two values after type conversion. If the types differ, it converts them using a set of rules: strings and booleans become numbers, objects are converted to primitives, and null and undefined equal each other but nothing else. That leads to surprising results like 0 == '' and '1' == true both being true.
Because the rules are hard to remember, most code uses strict equality, ===, instead. One common, deliberate use of == is x == null, which checks for both null and undefined.
With objects, == compares references just like ===: two separate objects are never equal, even with the same contents. When comparing an object to a primitive, the object is converted with valueOf() or toString() first. NaN == NaN is false, as with strict equality. Linters such as ESLint's eqeqeq rule can enforce === throughout a project.
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





