0

I read this in Eloquent JavaScript book:

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.

Because of this, expressions like 0 == false and "" == false are true.

And also following these rules this expression should evaluate to true:

console.log("A" == true)

But it evaluates to false. Why?

4
  • 1
    You are not actually casting string "A" to boolean; you're comparing a string and a boolean, which is a different thing and it's definitively not solved by casting the left operand to the type of the right operand. If you check the accepted answer in the linked question, I reckon that rule #10 applies. Commented Dec 5, 2017 at 15:36
  • 1
    @ÁlvaroGonzález: Actually, rule 7 applies: x == ToNumber(y) > "A" == 1 , which is false, of course. Commented Dec 5, 2017 at 15:42
  • 2
    @Cerbrus Oops, yes, you're right, I overlooked that. Commented Dec 5, 2017 at 15:43
  • Now I get it. It's not about truthy and falsy. Thanks guys @ÁlvaroGonzález Cerbrus Commented Dec 5, 2017 at 15:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.