Live data from Hacker News

JSFuck – Write any JavaScript with 6 Characters: []()!+

jsfuck.com

51–60 of 76 posts

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#51
post #28

"JSFuck is an esoteric and educational programming style" How exactly is this educational?

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'

Not 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

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#53

I saw a very cool security talk a few years ago about how you can use the browser to do all kinds of evil things (did you know that the Same Origin Policy does not prevent you from making the request, but just seeing the response? And even then, you can guess at what kind of response you got). One of the great points in the talk was JS obfuscation. Now, there are many techniques for doing this, but I really like this…

[deleted]

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#54

Currently, there is only 5 characters in the HN headline: "[]()+". Maybe a mod removed the "!" because they thought it was being used for emphasis. It could be placed before the "+".

A human would have probably noticed the "6 characters" part. I bet this was done automatically.

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#55
post #48
post #35

Earlier quoted context omitted.

Try it letter by letter. For instance, to get the string "a": (![]+[])[+[[+!+[]]]] Take the first part, `(![]+[])`. `![]` evaluates to `false`. Then `+[]` coerces false into a string, so the expression is `"false"`. The rest of the expression (more complicated) evaluates to `[[1]]`, which will grab the `"a"` from `"false"`. Now why there is the extra surrounding brackets, I'm not sure, because `[1]` would have worked…

It looks like the generator is suboptimal, but still really cool. (![]+[])[+!+[]] evaluates to "a" as well. It looks like it turns it into an array twice. It goes +!+[] === 1 then [+!+[]] === [1] then +[[+!+[]]] === 1 then [+[[+!+[]]]] === [1]

Ah! You're right. Confusing.

Also confusing that "false"[[1]] works.

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#58
post #28

"JSFuck is an esoteric and educational programming style" How exactly is this educational?

By 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.

Re: JSFuck – Write any JavaScript with 6 Characters: []()!+

#59

I saw a very cool security talk a few years ago about how you can use the browser to do all kinds of evil things (did you know that the Same Origin Policy does not prevent you from making the request, but just seeing the response? And even then, you can guess at what kind of response you got). One of the great points in the talk was JS obfuscation. Now, there are many techniques for doing this, but I really like this…

I am worried about the file size.
Post reply on HN