Recently, a post appeared on Reddit explaining why the construction [[] [[]] + []] [+ []] [++ [+ []] [+ []]] in JavaScript is calculated as an “n” character. We translate it for you.
So, let’s start with an empty array:
[]
Now we get access to the element of the empty array:
[] []
Which element? Let this be an element with an index of an empty array:
[] [[]]
This value is not defined, ie. is equal to undefined, but if to add to it an empty array the string “undefined” turns out:
[] [[]] + []
Let’s wrap it with an array:
[[] [[]] + []]
Now let’s try to access the letters of this line. To begin, we need to access the string itself inside the array:
[[] [[]] + []] [0]
But zero can be obtained if you convert an empty array to a number:
[[] [[]] + []] [+ []]
The letter “n” is the second in the word “undefined”, so its index is 1:
[[] [[]] + []] [+ []] [1]
But how do we get 1? Of course, increase by 0, which we have learned to get before:
++ [0] [0]
And, as before, zeros can also be written in parentheses:
++ [+ []] [+ []]
So, let’s put it all together and get:
[[] [[]] + []] [+ []] [++ [+ []] [+ []]]