The expression thing[2]
means to find a property on the object named thing
with the name "2"
. Since property names are strings, the number 2
is automatically converted to the string "2"
. Since that object has no such property, the result is undefined
.
The expression thing[2+3]
means to first evaluate 2+3
which is 5
. Then 5
is converted from a number to a string "5"
, and then find the property on thing
with that name. Thus the result is 20
.