marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Chapter 1: Automatic type conversion #410

Closed rangitha closed 6 years ago

rangitha commented 6 years ago

From the 3rd edition:

The rules for converting strings and numbers to Boolean values state that 0, NaN, and the empty string ("") count as false, while all the other values count as true.

However, in DevTools of Chrome 65:

false == false
// true

false == 0
// true

false == ""
// true

false == NaN
// false

I can't remember what the result of the last expression was when I read the 2nd edition. But it doesn't look like it's applicable anymore.

marijnh commented 6 years ago

This is about converting to boolean, not comparing with a boolean value. That's a different set of rules, which is mentioned elsewhere in the chapter.