Why in javascript:
>1+[[]+[]]-[]+[[]-[]]-1 9
In general, it is difficult at first glance to understand why.
What do you think
[[]+[]]-[]+[[]-[]]==9
?
')
And here is no:
> [[]+[]]-[]+[[]-[]] "00"
But we know that when added to a line in JS, concatenation occurs, and then the first expression would seem to be 99:
> 1+"00"-1 99
How so?
We'll have to disassemble from the beginning, first about two zeros:
> []+[] ""
Here it is clear that empty arrays turned into empty lines and when folded together they gave rise to an empty string.
> [""]-[] 0
It is also understandable here, if you understand that the second empty array is from the point of view of arithmetic zero, and the empty string (to which the first array is given for arithmetic) is also zero. Zero minus zero as long as it makes sense. The second part also becomes immediately clear:
> [[]-[]] [0]
So we have a normal zero, and a zero in the array, adding them, is reduced to lines and concatenated:
> 0+[0] "00"
With double zero everything is clear. Where did the 9 come from?
We read the addition, as expected, from left to right:
> 1+[[]+[]] "1"
With a large number of square brackets we already understood, an array with an empty string led to an empty string and turned the whole unit into a one-line ...
> "1"-[] 1
... and then subtracting zero turned it back into an integer.
> 1+[[]-[]] "10"
The set of square brackets on the right is ["0"], which turns into a string representation of the array, and is added to the unit, which again turned into a string for this.
And the final chord is quite obvious:
> "10"-1 9
And it looks all right ...
In general, people make the full language of the Javascript interpreter using only the characters of brackets, the exclamation mark and plus:
http://www.jsfuck.com/ and then use it to bypass filtering by regular expressions in eBay:
http://thedailywtf.com/articles / bidding-on-security