If {}object, e.g. {}"string", {}[1, 2, 3], or {}({}) is exactly equal (according to ===) to object, e.g. "string", [1, 2, 3], or ({}), why can you define a variable with the latter but not the former?
To clarify:
{}"string" === "string" // true
var a = "string" // No error
var a = {}"string" // SyntaxError: Unexpected string
var a = ({}"string") // SyntaxError: Unexpected string
var a = {}("string") // TypeError: object is not a function
var a = ({}("string")) // TypeError: object is not a function
In this context, the
{}seems to be behaving like an empty block, not as an object literal. So think of it syntactically like:However, that empty block cannot be used on the right side of an assignment like
And here, the
{}()implies that{}is being used as a function, with parameters inside()