1

Possible Duplicate:
Can you explain why ++[[]][+[]]+[+[]] = 10

As we all know that Cheat sheets are the shortest ways we can find to accomplish things by using the charsets. I cant uderstand how it is getting executed. Can any one clarify?

How "NaNundefined"[10] ="e" Or ([+[][[]]]+[][[]])[++[[]][+[]]+[+[]]] = "e" ?

Community
  • 1
  • 1
Amar
  • 353
  • 1
  • 2
  • 13
  • I'm sorry but I'm having a hard time understanding exactly what you are asking here... – Lix Feb 01 '13 at 12:21
  • 3
    `"NaNundefined"[10]` refers to the 11th character of that string which is `"e"`. `([+[][[]]]+[][[]])` is just an obfuscated way of producing `"NaNundefined"` and `++[[]][+[]]+[+[]]` the same for producing `10`. But I 'm not sure what the purpose of the question is. – Jon Feb 01 '13 at 12:21

2 Answers2

6

"NaNundefined"[10] ="e" is easy - e is the eleventh char in the string.

([+[][[]]]+[][[]])[++[[]][+[]]+[+[]]] = "e" is a bit harder, but you can easily just split it up:

[+[][[]]] -> [ NaN ]
[][[]] -> undefined
[ NaN ] + undefined -> "NaNundefined"
++[[]][+[]] -> 1
[+[]] -> "0"
1 + "0" -> "10"
"NaNundefined"["10"] -> "e"

The second version is effectively a way to construct the first, (ab)using the weak typing of javascript operators (for example, [NaN] + "" -> "NaN"). It also uses the fact that arrays in javascript are always indexed by a string (so array[10] is equivalent to array["10"]).

The second version could be seen as a obfuscation, if you want to prevent someone to understand the code. It doesn't really serve much of a purpose though, at least in everyday coding life.

Femaref
  • 60,705
  • 7
  • 138
  • 176
0

The character at index 10 is an e: "NaNundefined"[10] ="e"

bidifx
  • 1,640
  • 13
  • 19