First, [4,5,6][1]
evaluates to the number 5
Then, the +
operator is being applied to a first argument which is an Array
and not a Number
, so javascript assumes you're doing a string concatenation, not addition. Your array [1,2]
becomes a string, which is "1,2"
. You can see this yourself with [1,2].toString()
.
The number 5
is now being appended to a string, so it to gets converted to a string, and appended together to get "1,25"
.