Module 2 · Types, Operators and Coercion: Why '5' + 2 Is Not 7
Under the Hood: The Abstract Equality Algorithm and Floating Point
ProReading
Maria has a table that says [] == false is true, and she does not trust tables. "But why?" she asks. Nobody chose that answer by hand. A short algorithm in the language's specification produces it, and you can run that algorithm with a pencil. This lesson does exactly that, four times, and then opens the number itself.
Checking what this lesson needs for you…
What is inside Under the Hood: The Abstract Equality Algorithm and Floating Point
- Where the rules live: ECMA-262
- IsLooselyEqual, step by step
- ToPrimitive: how an object becomes a primitive
- ToNumber: the table behind every conversion
- Four walks through the algorithm
- The one number type: an IEEE 754 double
- The performance lab: 0.1 against 1, a million times