[Solved] What is !+[]+!+[] in javascript? [closed]


Breaking down the expression into the correct order of operations, you have:

(!(+[])) + (!(+[]))

First things first, [] is cast to a number by +, which results in 0. Don’t ask me why, it just does :p Probably buried in the specification somewhere.

!0 is simply true

So you end up with true + true, which again casts to numbers, resulting in 1 + 1 = 2

To get nine, you’d need nine repetitions:

!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[] == 9

1

solved What is !+[]+!+[] in javascript? [closed]