r/ProgrammerHumor • u/_hoh_ • Sep 04 '17
[[][[]]+[]][+[]][++[+[]][+[]]] is "n" in javascript
[[][[]]+[]][+[]][++[+[]][+[]]]This evaluates to "n" in javascript. Why?
Let's start with an empty array
[]Now, let's access a member of it.
[][]What member? Let's check for the empty array member
[][[]]oh, that is undefined. But if we add an empty array to that, it is casted to the string "undefined"
[][[]]+[]Let us wrap that in an array
[[][[]]+[]]We can now try to access letters in that string. First, we must unwrap the string. That can be done by accessing the first element of that array.
[[][[]]+[]][0]0 can be created by casting an empty array to a number:
[[][[]]+[]][+[]]Now, "n" is the second letter in that string, so we would like to access that:
[[][[]]+[]][+[]][1]But how can we write 1? Well, we increment 0, of course. Wrap 0 in an array, and increment the first member of it:
++[0][0]Like before, this is equivalent to
++[+[]][+[]]So our final code is then the glorious
[[][[]]+[]][+[]][++[+[]][+[]]]
462
u/[deleted] Sep 04 '17
Hey sorry but I only understand code when the IDE has colours so can you repost this just with colours and stuff thanks
9
u/washburnello Sep 04 '17
I'm not a programmer but it looks like you could use this to output any character in "undefined".
Could someone adjust this to output "f" so I can paste it when paying respects?
1.5k
u/grugbog Sep 04 '17
You can then go wild at jsfuck.com
1.9k
u/hikarikouno Sep 04 '17
Well...on the bright side, the array starts at 0.
597
u/cicuz Sep 04 '17
(╯°□°)╯︵ ┻━┻
105
u/AyrA_ch Sep 04 '17
Fizzbuzz
59
u/OvrDoseDnHAM1001 Sep 04 '17 edited Sep 04 '17
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]
398
u/wcscmp Sep 04 '17
So JS may actually be Turing complete.
Big day for JS community.
94
u/Centime Sep 04 '17 edited Sep 04 '17
You might like some of my previous work.. :)
http://centime.org/reverJS (Wrap your javascript code into a ~palindrome)
http://centime.org/jsfsck (JSFuck without parenthesis)
https://github.com/centime/jsEncode (Compact text to js encoder)
also, alert(1) in 99 chars:
([,ウ,,,,ア]=[]+{},[ネ,ホ,ヌ,セ,,ミ,ハ,ヘ,,,ナ]=[!!ウ]+!ウ+ウ.ウ)[ツ=ア+ウ+ナ+ヘ+ネ+ホ+ヌ+ア+ネ+ウ+ホ]ツ()
42
u/[deleted] Sep 04 '17 edited Sep 04 '17
is this going to be my next whiteboard problem for my sr engineering interviews I have this week?
26
u/TimVdEynde Sep 04 '17
Related blog post
19
u/ktkps Sep 04 '17
Interesting, now if someone can replicate this in minecraft running on ReactOS...
17
u/siedler084 Sep 04 '17
OP are you alright? I am kind of worried about your sanity
16
u/[deleted] Sep 04 '17
Fuck you, that's why.
42
u/Char-11 Sep 04 '17
I dont understand this but fuck it im upvoting anyways
9
u/redtoasti Sep 04 '17
Zuse died for this...
7
u/RDrazard Sep 04 '17
Magic 8 Console, do I truly understand JavaScript?
6
u/RANDOM_TEXT_PHRASE Sep 04 '17
I want that on a poster.
6
u/Burning_Lovers Sep 04 '17
javascript is like my ex: completely insane and hates me for no apparent reason
6
u/Neker Sep 04 '17
Thanks for this brillant explaination !
In a few years, when I finally wrap my head around it, I will be able to proudly say "Now I understand how variables work in JavaScript".
Serious, it's great.
Now, I wonder, what would Crockford say ? Which of those are luminous insight into the essence of programming, and which are design flaws inherent to a language that was hastily cobbled together ?
The
let's check the empty array member of an empty arrayis genius to me. Of course it looks silly at first, and useless, but what happens when you iterate over truckloads of collections of data originating in real life ? Surely this case will happen and must be guarded against, or else NPE in your face. With js, none of that whinny nonsense. We are gracefully informed that the requested value isundefined, a perfectly legal and meaningfull value, and we can go on. Neat, concise, unobstrusive.But then
is a mystery to me. Well, at least it is casted to something, which allows continuing execution and eventual detection. I'd rather feel inclined however to think that it should cast to
undefinedagain. Maybe somebody should write an algebra for undefined values like Boole did for truth values.5
u/PioIsPro Sep 04 '17
I N E E D W H O L E A L P H A B E T
9
u/soenderup Sep 04 '17
"Good code is often overlooked" XD
4
u/t3hcoolness Sep 04 '17
How does this work with letters not in "undefined"?
4
u/Tiavor Sep 04 '17
but can you write "Hello World!" with it?
9
u/[deleted] Sep 04 '17
I both hate and love JavaScript. This is why.
6
u/vwibrasivat Sep 04 '17
Thank you, Satan.
3
u/[deleted] Sep 04 '17
Jesus Christ.. thought that was a joke post...
I was wrong... very wrong...
3
u/Azwraith42 Sep 04 '17
'N' from not a number = [[+[]]/[+[]]+[]][+[]][+[]]
'n' from Infinity = [++[+[]][+[]]/[+[]]+[]][+[]][++[+[]][+[]]]
3
u/Ghi102 Sep 05 '17
So JavaScript is secretly a Brainfuck interpreter too.
3
u/[deleted] Sep 05 '17
This probably won't ever get read by anyone but... wat is a great overview of some of the more ridiculous things in this language.
3
u/askeeve Sep 05 '17
5
u/Blu3Dev Sep 04 '17
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]()
2
u/[deleted] Sep 04 '17
You are a marvelous human being. I want to be your friend!
2
u/Not_sure_if_george Sep 04 '17
If only Howard Stern hadn't already used up the term pig vomit. It would be a much better name for JavaScript.
2
u/rk-imn Sep 04 '17
JSFuck
2
u/Hestmestarn Sep 04 '17
What the fuck
2
u/[deleted] Sep 04 '17
Someone should create a language that consists of nothing but array literals and array accessors and achieves Turing completeness through implicit conversions.
2
u/embersyc Sep 04 '17
Python doesn't like it:
Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers or slices, not list
2
u/betheking Sep 04 '17
Jesus, it took me almost 10 seconds to get the joke. Good one.
2
u/pedropants Sep 04 '17
If javascript winds up being turing complete with just [, ], and +, i'm going to become very afraid.
2
u/petdance Sep 05 '17
And people give me shit about my love for Perl.
2
u/popeter45 Sep 05 '17
does this prove Javascript == JS Fuck?
2
u/Never-asked-for-this Sep 05 '17
What in the ungodly fuck is that?...
2
u/jaketr00 Sep 05 '17
In that case, I could say
this makes me want to
[[][[]]+[]][+[]][++[++[+[]][+[]]][+[]]]+[[][[]]+[]][+[]][++[++[++[++[++[+[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[][[]]+[]][+[]][++[++[++[+[]][+[]]][+[]]][+[]]]3
u/IamaScaleneTriangle Sep 04 '17
wat
3
u/[deleted] Sep 04 '17
JavaScript was a mistake.
2
u/link6112 Sep 04 '17
So I was considering learning JavaScript....
2
u/fiddlededoo Sep 04 '17
As if I needed more reasons to hate Javascript.
2
u/thatguyastro Sep 04 '17
If anyone wants to try this, open the Google Developer console on Chrome (ctrl+shift+j on Windows, alt+cmd+j on Mac), and simply page "[[][[]]+[]][+[]][++[+[]][+[]]]", you'll get an output on "n".
1
u/owshi Sep 04 '17
Do you even js? https://github.com/denysdovhan/wtfjs
1
u/InsaneThespian Sep 04 '17
Blood. All I see is blood.
1
u/MrTarantula Sep 04 '17
I made an npm library for this a few weeks ago! I wanted to limit myself to just {[(!:)]} characters, and not make each letter more than 100 characters, so I haven't gotten very far, but here it is:
Beardfondle
1
u/NAN001 Sep 04 '17
/r/accidentalbrainfuck
1
u/[deleted] Sep 04 '17
I started to play with this and just realized it was making me angry.
1
u/Houdiniman111 Sep 04 '17
FYI, your RES tag is now
1
u/[deleted] Sep 04 '17
This was fucking beautiful! Top notch! Have an upvote sir!
1
u/apieceoffruit Sep 04 '17
just picking the letter N? bah
Here is a much funnier explanation of the above
1
u/msg45f Sep 04 '17
1
u/EstebanZD Sep 04 '17
I only saw loops between loops and increments in sectors.
1
u/rpungello Sep 05 '17
wat
1
u/therealpoorno Sep 05 '17
Can someone tell me what this all means
1
u/AJdoubleU Sep 05 '17
How do I make this spell my username?
1
u/DrCaptainScientist Sep 06 '17
I put untrusted code in f12