Live data from Hacker News

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

jsfuck.com

11–20 of 76 posts

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

#12
That's a pretty awesome hack of JS's (rather insane) semantics. It's probably worth understanding at least the primative examples though if you're a JS programmer, because this actually happens sometimes to expressions you write.

For a little bit of insight into why []+[] === '', for example, check this out: http://www.2ality.com/2012/01/object-plus-object.html

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

#15
post #14

I put in alert('hello') and it worked. That's awesome. But how? I searched the code it made and didn't see 'hello.' I understand the stuff below, how it uses JS's weird properties to the basic types... but how does it encode characters?

It converts certain things into strings. Like [][[]] => undefined, and then gets the characters by index from that string and puts your original string together.

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

#16
post #14

I put in alert('hello') and it worked. That's awesome. But how? I searched the code it made and didn't see 'hello.' I understand the stuff below, how it uses JS's weird properties to the basic types... but how does it encode characters?

Im not sure but once you have 0, 1, 2 and 10 as numbers you could add and subtract those to get any number you want, then express those numbers as strings (casting).

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

#17
post #14

I put in alert('hello') and it worked. That's awesome. But how? I searched the code it made and didn't see 'hello.' I understand the stuff below, how it uses JS's weird properties to the basic types... but how does it encode characters?

Look at the source.

It uses various techniques to get at e.g. type names, and then uses string indexing to access characters in the type name. It has enough characters like this to be able to call fromCharCode.

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

#19
post #6
post #2

While funny looking, what is the ingenuity behind it?

Many people here on HN never took compsci in school, so strictly speaking it's just a translator - http://en.wikipedia.org/wiki/Translator_(computing) . It's more a showoff of a js idiosyncrasy - they found an ugly looking subset of characters that is Turing complete and wrote a translator to it. If you're new to the concept of Turing tarpits, then this should blow your mind. On the other hand, this is a sufficiently…

Also worth mentioning the inspiration (and why the name has "fuck" in it): http://en.wikipedia.org/wiki/Brainfuck
Post reply on HN