Decrease JavaScript Enforcement

Can someone help me in demystifying the following expression:

++[[]][+[]]+[+[]]

My understanding Go from left to right:

  • ++[[]]: Not sure what it will evaluate and how.
  • [+[]]: First, a [+] run will be executed, and the unary operator will try to convert [] to a number. Therefore, 0. Thus, the output [+ []] will be [0].
  • [+[]]+[+[]]: which is [0] + [0]. The array toString () method will be called here, and the output will be "00".

Basically, I cannot understand the left most expressions, i.e. ++[[]]

+4
source share
2 answers
++[[]][+[]]+[+[]]

The expression will be split into two, as shown below.

  • ++[[]][+[]] and [+[]]

Now [+[]]evaluated as [0](as you already understood.)

++[[]][+[]], ++([[]][+[]]):

()

  • ++[[]][0]

[[]] - , . , [[]][0] [], .

, 0- , 0 , , , 0- , ++ .

, ++[[]][+[]], , 1.

1+[0] i.e. 1+[0].toString() i.e. 1.toString()+"0" i.e. "1" + "0" i.e. 10.

+4

[+[]] [0]

++[[]][+[]] 1

1 + [0] "10" javascript

0

All Articles