+ 3

Why does ++[[]][+[]]+[+[]] return the string "10"?

15th Oct 2018, 1:03 PM
1704086_ibnul
1704086_ibnul - avatar
2 Answers
+ 6
This is posted as a possible hint. I got this far before getting pulled away: var z = ++[[]][+[]]+[+[]]; Using typeof and alerts, here's (I think) the right hand side (after ++[[]]) [] object: (empty array) +[] number: empty value coerced by leading sign to 0 [+[]] object: Array with 1 element: 0 + [+[]] number: leading sign coerces single value, BUT [+[]] + [+[]] string: + coerces concatenation context between OBJECTS The left hand side prefix and [[]] appears to somehow select the left-hand side of the string and increment the first digit, because trying to separate them reports "invalid left side". This has similar functionality if you flip it so it works for the right hand side (notice [[]] is moved to the right and now postfix addition): [+[]]+[+[]][[]]++ Output: 0NaN I know at least one javascript obfuscator leverages this syntax, ...if you want to dig at what I used to generate this: https://code.sololearn.com/Wo4ysbH3jwcn/?ref=app (See code's app comments)
15th Oct 2018, 7:53 PM
Kirk Schafer
Kirk Schafer - avatar