null + {0:1}[0] + [,[1],][1][0] 

    1 answer 1

    First of all, you need to decide on what exactly develops:

    1. null
    2. {0:1}[0] -> 1 // access to the object field
    3. [,[1],][1][0] -> [1][0] -> 1

    As a result, we get

     null + 1 + 1 

    Further we turn to the specification , and we get the following

     ToNumber(null) + ToNumber(1) + ToNumber(1) 

    In the same specification, we see that ToNumber(null) == +0

    As a result, we get

     +0 + 1 + 1 

    That equals: 2


    It is also worth paying attention to the fact that in this case not arrays are added, but the specific value of the object property, and the specific element of the array.

    • Why in the third action from the array [, [1],] [1] [0] it turns out [1] [0]? - Nikita
    • one
      [,[1],][1][0] === ([,[1],][1])[0] === ([1])[0] === [1][0] === 1 - Arnial
    • one
      The second and third pairs of square brackets ([1] [0]) are not arrays, this is the sequential use of the index value retrieval operator (which is written in the form of square brackets with the index inside). - Arnial
    • one
      The array in the third example is only [,[1],] which is equivalent to an array of 2 elements [ <empty_slot>, [1] ] , where <empty_slot> is an uninitialized field. - Arnial pm