61 likes
·
2.9K reads
2 comments
When I open the console. I get this...
This is actually a good point to bring up.
The way that the specification for JavaScript is written, block statements are evaluated before expressions, so when the interpreter sees curly braces when not in an expression context, it interprets them as a block rather than an object literal. That's why you get an error when you attempt to run those expressions in the browser. The way to force the interpreter to see {} as an object literal instead of as a block is to wrap it in parentheses.
If you were to open a Node console rather than a browser console, you would see:
This is because Node made a change to evaluate input as expressions before evaluating them as statements. That change can be seen here.