The main reason is that {} means another thing in the context of the { statement0; statement1 } { statement0; statement1 } than in the context of the expression ({ "property": value, ... }) .
{} + []
- block and unary comparison operator, same as
{} // An empty block of statements. (+ []) // Use of prefix operator +.
Another is the use of the plus operator, which when used with two objects combines them, as in
return String({}) + String([])
Since Array.prototype.toString array, it looks like
return String({}) + [].join(",")
which boils down to
return "[Object object]" + "";
and finally to
return "[Object object]"
source share