This behavior is how JavaScript engine (e.g V8) starts out by parsing the source code into an Abstract Syntax Tree(AST). For {}, JavaScript parser considers it as an empty block because this is the first thing in the statement. But in the case of [] + {}, the first thing is an array followed by Addition operator.
Here's a nice AST explorer to check out. Paste both the statement to verify yourself. 🙂
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Ravina,
This behavior is how JavaScript engine (e.g V8) starts out by parsing the source code into an Abstract Syntax Tree(AST). For
{}
, JavaScript parser considers it as an empty block because this is the first thing in the statement. But in the case of[] + {}
, the first thing is an array followed by Addition operator.Here's a nice AST explorer to check out. Paste both the statement to verify yourself. 🙂