3 ms·
"JSFuck is an esoteric and educational programming style" How exactly is this educational?
by talles 13y ago
"JSFuck is an esoteric and educational programming style"
How exactly is this educational?
- MattBearman 13y agoI took the 'educational' to mean 'this should never be used in a real application' :)
- prezjordan 13y agoIt 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)")()
- ctdonath 13y agoBy demonstrating creative abuse of a language, one can better understand what the language constructs do and the scope of their capability. The comparable IOCCC.org contest is a great place to learn C: sure the primary focus is making obfuscated code, and the audience marvels at the bizarreness thereof, but taking the time to pick a submission apart and figure out why it works (despite a host of reasons why you'd think it shouldn't) expands your understanding of the language. It's a great way to improve your language skills when you've reached the initial "I know language X" confidence.