When you see {}
character at the beginning it is interpreted as a empty block
or empty
object literal(when you're creating objects).
When you're using an expression
or statement, +
represent the plus operator, which coerces
its operand(in this case it will be []
) to a number.
So +[]
is the same as Number([])
, which evaluates to 0.
The unary
plus
operator internally use the ToNumber
abstract operation.
Read more about Type Conversions and operators.
With the other words, {} + []
expression is an empty
code block followed by an array
which will be constraint to a number(Number[]
).
In the second example you're providing you just concat
an object literal(empty object) to an array. That't why you're receiving [object Object]
.