javascript – Can you explain why ++[[]][+[]]+[+[]] = 10

Posted: December 29, 2011 Comments(1)

javascript – Can you explain why ++[[]][+[]]+[+[]] = 10 – Stack Overflow.

Not only is the original post itself interesting, but the fact that someone took the time to so delicately (and thoroughly) explain an answer is what really got me. I’m not usually one to put too much emphasis on or value in 100% crowdsourced endeavors, but this is not the first thread like this I’ve seen on StackOverflow, and I can’t tell you how many times Googling has sent me to the site with a very to-the-point answer. For me, StackOverflow breaks the norm in that regard.

If you’re not actively taking advantage and participating in this community, I’d like to strongly encourage you to try and make that a habit. We are saturated with smart people, and this thread goes to show you that sometimes you should just ask.

A lot of pride comes from figuring out something on your own, but with that comes a sheltered experience that likely would be more worthwhile and valuable had you consulted someone else. It’s difficult to strike a balance between self education and flat out asking questions, but I think it’s an important balance to find.

Get my newsletter

Receive periodic updates right in the mail!

  • This field is for validation purposes and should be left unchanged.

Comments

  1. Let’s make it simple:

    ++[[]][+[]]+[+[]] = 10
    
    var a = [[]][+[]];
    var b = [+[]];
    
    // so a == [] and b == [0]
    
    ++a;
    
    // then a == 1 and b is still that array [0]
    // when you sum the var a and an array, it will sum b as a string just like that:
    
    1 + '0' = 10

Leave a Reply

Your email address will not be published. Required fields are marked *