Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Truthiness of Integer Arrays #17

Closed
ramadis opened this issue Feb 10, 2016 · 1 comment
Closed

JS: Truthiness of Integer Arrays #17

ramadis opened this issue Feb 10, 2016 · 1 comment

Comments

@ramadis
Copy link

ramadis commented Feb 10, 2016

Hey! The issue you are seeing there with [0] is not an issue at all. The behaviour is completley normal if you embrace JS coercion (implicit casting) in == operator.

the issue is that in the expression [0] == false, false is actually coerced to a Number by the built-in object Number, and of course: Number(false) is 0!
Then, [0] is first coerced to the String "0" and finally coerced to the Number 0.
So, the last comparision is actually 0 === 0. Which is obviously true.

Hope the explanation shed some light on the subject!

@jbranchaud
Copy link
Owner

Thanks for walking through the coercion rules. This makes more sense now. I don't think I can embrace JS coercion rules though 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants