2

In Javascript, how can an element of 1+ elements return false if compared to a boolean?

> [1, 2] == true
< false
> [1, 2] == false
< false

I know that if the array contains only a 0 or a 1 a casting will be done and the comparison will return true if 0 is compared to false or if 1 is compared to true.

Jac
  • 531
  • 1
  • 4
  • 19
  • 1
    From spec: `If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).` -> it checks ` == `, which does not fulfill any of the conditions in Abstract Equality Comparison, and returns `false` – CertainPerformance Mar 01 '19 at 10:55
  • Thanks, it did not look clear to me that no condition was met, especially since `[0] == false -> true` was still doing a casting, but I guess that is covered in `11.` in the link you provided – Jac Mar 01 '19 at 11:03

0 Answers0