Learn JavaScript

Lesson 5 of 9 · Types, Operators and Coercion: Why '5' + 2 Is Not 7

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

  1. Where the rules live: ECMA-262
  2. IsLooselyEqual, step by step
  3. ToPrimitive: how an object becomes a primitive
  4. ToNumber: the table behind every conversion
  5. Four walks through the algorithm
  6. The one number type: an IEEE 754 double
  7. The performance lab: 0.1 against 1, a million times