January 2020
Intermediate to advanced
548 pages
13h 36m
English
Numeric comparison using JavaScript's greater-than and less-than operators is fairly intuitive. As mentioned, your operands will be coerced first to their primitive representations, and then coerced a second time, explicitly, to a number. For cases where both operands are numbers, the result is entirely intuitive:
123 < 456; // => true
And for NaN and Infinity, the following assertions can be made:
Infinity > 123; // => trueInfinity >= Infinity; // => trueInfinity > Infinity; // => falseNaN >= NaN; // => falseNaN > 3; // => falseNaN < 3; // => false
If one operand has a primitive representation that is not Number, then it will be coerced to Number before comparison. If you were to accidentally pass Array as an operand to ...
Read now
Unlock full access