Hacker News new | ask | show | jobs
by Hupo 4886 days ago
The fun thing about JavaScript's type coercion and concatenation is that you can use it to create fun brain benders like this:

  +[[+!+[[]]]+[![]][+[[]+[]]]++] === 10
This evaluates to true. Cookie for anyone who can explain why!
1 comments

I gues it could be because + infront of an empty array returns 0. So, when you do !+[] you get 1. What you pasted it a bit of a labyrinth, but if someone bothered to keep track of it, they could definitely find ten 1s in there. It's not why, it's a how.

I hope someone figures out the rest and gets a cookie! :D