Demistify Coercion in JavaScript

Viewed 80

Can somebody help me in demystifying the following expression:

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

My Understanding Going from left to right:

  • ++[[]]: Not sure what this will evaluate to and how.
  • [+[]]: The +[] will be executed first and the unary operator will try to convert [] to number. Hence 0. So the output of [+[]] will be [0].
  • [+[]]+[+[]]: Which is equal to [0] + [0]. Here both the array's toString() method will be called and the output will be "00".

Basically I am not able to understand the left most expression i.e. ++[[]]

2 Answers
Related