TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
== (abstract equality) operator evaluates whether two operands are equal by applying the ECMAScript Abstract Equality Comparison algorithm. Unlike the strict equality operator (===), if the operands are of different data types, the JavaScript runtime implicitly converts (coerces) them to a common type before performing the comparison.
Type Coercion Mechanics
When evaluatingx == y, the runtime applies the following primary coercion rules:
- Null and Undefined:
nullandundefinedare considered loosely equal to each other, but not to any other values. - String and Number: If one operand is a string and the other is a number, the string is converted to a number via the internal
ToNumberoperation. - Booleans: If either operand is a boolean, it is converted to a number (
truebecomes1,falsebecomes0) before further comparison. - BigInt: If a
bigintis compared to anumber, they are compared by their mathematical value without coercion. If astringis compared to abigint, the string is converted to abigintusing the internalStringToBigIntoperation. - Objects and Primitives: If one operand is an object and the other is a primitive (string, number, bigint, or symbol), the object is converted to a primitive using its internal
ToPrimitivemethod (typically invokingvalueOf()ortoString()).
Syntax
TypeScript Compiler Behavior
While TypeScript emits standard JavaScript== at runtime, its static type checker restricts abstract equality comparisons during compilation. If the TypeScript compiler determines that the types of the two operands have no overlap, it will throw a ts(2367) error, preventing the comparison of mutually exclusive types. To trigger runtime coercion in TypeScript without compiler errors, at least one operand must be typed as any or unknown, or the types must share a union.
Evaluation Order
- If the operand types are identical, the operator performs a strict equality comparison (identical to
===). - If the operand types differ, the runtime attempts type coercion based on the ECMAScript specification.
- The newly coerced values are compared.
- The expression resolves to a boolean (
trueorfalse).
Master TypeScript with Deep Grasping Methodology!Learn More





