++[]: lvalue is an empty array, not a legal lvalue, so an error is reported.
What is left value:
Lvalue is an old term that means an expression can only appear on the left side of the assignment operator. In JavaScript, variables, object properties and array elements are all lvalues.
++[[]][0]
:[[]]
是一个只包含一个空数组的数组,那么根据运算符优先级,[] > (prefix)++
,运算[[]][0]
,得到一个空数组Array(0)
,是一个对象,并且是数组中的一个值,符合左值的条件.之后进行(prefix)++
运算,由于++
运算将执行数据类型转换(PS:Javascript中具体的数据类型转换太复杂了,我就不展开了),这里Array[0]
将转换成0
,结果++
Get 1.Please see the console output for details:
++[]
: lvalue is an empty array, not a legal lvalue, so an error is reported.What is left value:
I have answered this question before and posted the link directly:
js type conversion problem