-2

I saw _=$=+[],++_+''+$ that evaluates to 10 in this question Why does ++[[]][+[]]+[+[]] return the string "10"?. ( http://jsfiddle.net/tVMqM/ ).

Can someone please explain me why?

Community
  • 1
  • 1
user1365010
  • 3,185
  • 8
  • 24
  • 43
  • 2
    Honestly these exercises are only valuable if you figure them out yourself. Take the expression apart piece by piece; draw a syntax diagram. – Pointy Jun 11 '12 at 12:57
  • 3
    Doesn't the answer to the question you posted explain it? – woz Jun 11 '12 at 12:57
  • I think you'll find a lot of answers in the post you linked. Basically, its string concatenation of `1` and `0` making `10`. – Curtis Jun 11 '12 at 12:58
  • 1
    `-~[]+[~~[]]` also equals to 10 ;) – Clyde Lobo Jun 11 '12 at 13:02
  • The link you provided already includes an in-depth answer to your question. See the post by 'pimvdb' at http://stackoverflow.com/questions/7202157/can-you-explain-why-10 – LeigerGaming Jun 11 '12 at 12:58
  • 1
    Glad this was closed. StackOverflow could be flooded with an endless combination of expressions evaluating to some magic result. These have no usefulness in the real world, and as @Pointy stated, are only really valuable if you work them out yourself. –  Jun 11 '12 at 13:05

2 Answers2

7

Resolves to 1 (true) _=$=+[],++_

Converts it to a string +''

Adds 0 to string +$

Edit: More detail for first part...

Create variables _ and $ _=$=

Set variables equal to 0 +[]

Increment _ variable ++_

jeffjenx
  • 17,041
  • 6
  • 57
  • 99
4

There's a pretty good explanation here. HackerNews has some great discussion on the topic here.

It's important to note that this isn't the integer 10, but rather the string "10".

SomeKittens
  • 38,868
  • 19
  • 114
  • 143