The less than (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
<) operator is a binary relational operator that evaluates whether the left operand is strictly smaller in mathematical or lexicographical value than the right operand, returning a boolean (true or false).
Evaluation Algorithm (Abstract Relational Comparison)
When the JavaScript engine evaluatesx < y, it executes the Abstract Relational Comparison algorithm. This dictates how different data types are coerced and compared:
- Primitive Coercion (
ToPrimitive): The engine converts both operands to primitive values. If an operand is an object, it invokes its[Symbol.toPrimitive](),valueOf(), ortoString()methods, with a hint ofNumber. - String vs. String: If both resulting primitives are strings, the operator performs a lexicographical comparison. It compares the strings character by character from left to right, based on their 16-bit unsigned integer UTF-16 code unit values.
- Numeric Conversion (
ToNumeric): If at least one of the resulting primitives is not a string, the engine coerces both operands to numeric values (eitherNumberorBigInt) before comparing.
Type Coercion Rules and Edge Cases
NaN(Not-a-Number): If either operand isNaN, or coerces toNaN(e.g.,undefined, unparseable strings, or arrays with multiple elements), the operator always returnsfalse.- Booleans:
truecoerces to1andfalsecoerces to0. - Nullish Values:
nullcoerces to0.undefinedcoerces toNaN. - Zeroes:
+0and-0are considered mathematically equal, so-0 < +0evaluates tofalse. - BigInt vs Number: When comparing a
BigIntto aNumber, JavaScript compares their exact mathematical values without implicit conversion, preventing precision loss.
Syntax Visualization
Numeric Comparison:Master JavaScript with Deep Grasping Methodology!Learn More





