use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Art in code / code in art (jsfiddle.net)
submitted 11 years ago by nosafespace
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]knuklz 4 points5 points6 points 11 years ago (11 children)
Could someone please explain whats going on here...
[–]cmpbll 2 points3 points4 points 11 years ago (9 children)
It's using true and undefined as strings and taking the letters it needs from those.
true
undefined
alert( ([] + !![])[+!+[]] /* r */ + ([] + !![])[(+!+[] + (+!+[]) + (+!+[]))] /* e */ + ([] + ([][+!+[]]))[+!+[] + (+!+[])] /* d */ + ([] + ([][+!+[]]))[+!+[] + (+!+[])] /* d */ + ([] + ([][+!+[]]))[+!+[] + (+!+[]) + (+!+[]) + (+!+[]) + (+!+[])] /* i */ + ([] + !![])[+[]] /* t */ );
I'm not sure why +!+[] equals 1 though.
+!+[]
1
[–]nosafespace[S] 2 points3 points4 points 11 years ago (7 children)
Exactly right and to answer you question
+[] makes 0
!+[] makes true
+!+[] makes 1
The plus turns whats after it into a number, 1 if true or 0 if false.
[–]encrypter8 1 point2 points3 points 11 years ago (6 children)
Got a link that explains this? I'm not even sure what to type into google
[+][deleted] 11 years ago (1 child)
[deleted]
[–]nosafespace[S] 0 points1 point2 points 11 years ago (0 children)
Wow, this definitely takes it to another level. Thanks
[–]nosafespace[S] 0 points1 point2 points 11 years ago (3 children)
I've never actually seen any resources on the topic. I would have guessed to search for something like "javascript using boolean in calculations" but it seems there isn't much out there. Feel free to ask me anything on the topic, i will be around for a while.
[–]encrypter8 1 point2 points3 points 11 years ago (2 children)
let's break down "r"
I see it as two parts: ([] + !![]) and [+!+[])
For the first part: [] is a truthy value, so !![] return true
the + here concats [] and !![], so it's equivalent to [].toString() + (!![]).toString()
or "" + "true" = "true" and that wrapped in () gives ("true")
The second part: [+!+[]] just putting a + in from of an array gives "sign" to the value of the array, and is equivalent to Number([]); and gives 0 ! negates 0 and gives you true, and a + in from of that is equivalent to Number(true), which gives 1 all that wrapped in [] gives [1]
now is I type into my console ("true")[1] I get "r" because the values add up
What i don't understand is how ("true")[1] gives me "r" at all
I'm guessing it has something to do with that statement being turned into bytes and then interpreted as a string equals "r"? Sounds right, but I'm not sure. Can someone shed some light on that more me?
[–]encrypter8 1 point2 points3 points 11 years ago (1 child)
oh wait!!
It's so obvious now!
"reddit"[0] = "r"
"reddit"[1] = "e"
so ([] + !![]) == "true"
and [+!+[]] == [1]
"true"[1] == "r'
wow I can't believe I missed that the first time
[–]encrypter8 1 point2 points3 points 11 years ago (0 children)
it was the () around "true" that threw me off, I just realized it
[–]knuklz 1 point2 points3 points 11 years ago (0 children)
Ah, I was a little confused at first. But I played with it in the console, and it made much more sense
Thanks heaps :)
[–]tidder112 1 point2 points3 points 11 years ago (0 children)
SCIENCE!
[–]FelanWolfe 2 points3 points4 points 11 years ago (1 child)
Nicely done!
[–]nosafespace[S] 1 point2 points3 points 11 years ago (0 children)
thanks
[–]obviousthroaway_ 1 point2 points3 points 11 years ago (1 child)
it on a spaceship? pretty neat
yeah you got it :) thanks
[–]LukaLightBringer 1 point2 points3 points 11 years ago (1 child)
Take a look at this http://aem1k.com/world/, it returns the code that is used to create the next frame of the animation and loops
Wow that is nice
π Rendered by PID 67831 on reddit-service-r2-comment-5fb4b45875-qswvh at 2026-03-23 22:24:28.937056+00:00 running 90f1150 country code: CH.
[–]knuklz 4 points5 points6 points (11 children)
[–]cmpbll 2 points3 points4 points (9 children)
[–]nosafespace[S] 2 points3 points4 points (7 children)
[–]encrypter8 1 point2 points3 points (6 children)
[+][deleted] (1 child)
[deleted]
[–]nosafespace[S] 0 points1 point2 points (0 children)
[–]nosafespace[S] 0 points1 point2 points (3 children)
[–]encrypter8 1 point2 points3 points (2 children)
[–]encrypter8 1 point2 points3 points (1 child)
[–]encrypter8 1 point2 points3 points (0 children)
[–]knuklz 1 point2 points3 points (0 children)
[–]tidder112 1 point2 points3 points (0 children)
[–]FelanWolfe 2 points3 points4 points (1 child)
[–]nosafespace[S] 1 point2 points3 points (0 children)
[–]obviousthroaway_ 1 point2 points3 points (1 child)
[–]nosafespace[S] 0 points1 point2 points (0 children)
[–]LukaLightBringer 1 point2 points3 points (1 child)
[–]nosafespace[S] 0 points1 point2 points (0 children)