4 ms·
It teaches you the funky behavior of JavaScript. For instance, `[]["filter"]` returns an empty function called filter. In order to get particular characters (f
by prezjordan 13y ago
It teaches you the funky behavior of JavaScript. For instance, `[]["filter"]` returns an empty function called filter.
In order to get particular characters (for example: f), the script uses "false"[0], where "false" is derived from adding ![] + [], and 0 is derived from +[].
Putting all of that together ($ node):
> (![]+[])[+[]]
'f'
- adamb_ 13y agoNot sure that []["filter"] is all that funky of an example as it's just grabbing the arrays prototype method "filter" using bracket notation. Here's some better examples of JS oddities: http://stackoverflow.com/q/9032856/1538708 http://stackoverflow.com/q/9032856/1538708
- kshay 13y agoThe funkiness is really that []["filter"]["constructor"] is a function that behaves like eval(), or rather, it returns a function that when called executes the string that was passed to the constructor function. That's how they're actually running the code. > []["filter"]["constructor"]("alert(1)")()