CKTIS / JavaScript
Loose equality operator (==)
The == operator compares values using specified conversion rules when operand types differ. Learn how it differs from ===, how null and undefined are treated, and why objects are compared by identity.
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 == rightThe == operator tests loose equality. If comparison completes normally, its result is true or false. Unlike ===, it may convert operands of different types. Do not confuse it with assignment =. For matching types it behaves like ===: NaN is not equal to itself, while +0 and -0 are equal.
Conversions depend on the pair of types, not on general “truthiness”. Comparing a Number with a String converts the string to a number. When a Boolean is compared with a value of a different type, false is converted to 0 and true to 1, even if the other operand is null or undefined. For example, when evaluating false == null, the algorithm converts false to 0, and 0 == null produces false. The expressions 5 == "5" and false == "" both produce true. A BigInt and a Number are equal only when they represent the same finite mathematical value; comparing a BigInt with a String requires successfully parsing the string as an integer.
null == undefined produces true, but null == 0 produces false. Ordinarily, value == null checks for either null or undefined; the legacy browser exception is document.all, which also satisfies that condition. Two objects are equal only if they are the same object, not merely because they have matching properties.
When comparing an object with an appropriate primitive value, == may invoke object-to-primitive conversion, which can execute user code and throw exceptions. Prefer === by default; use == when you deliberately want its conversion rules.
Examples
const item = {};
console.log(5 == "5");
console.log(5 === "5");
console.log(false == "");
console.log(null == undefined);
console.log(null == 0);
console.log(item == item);
console.log(item == {});
console.log(NaN == NaN);Result
true false true true false true false false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.