When {} + 1
is evaluated, the result is 1
. However, if you assign this expression to a variable like x = {} + 1
, the variable will contain the string "[object Object]1"
.
What causes the semantics of the right-hand side expression to change upon assignment? Shouldn't the right-hand side expression be consistent and "context-free"?