Sign in
Log inSign up
Amy Shackles

61 likes

·

2.9K reads

2 comments

Martijn Imhoff
Martijn Imhoff
Nov 25, 2020

When I open the console. I get this... image.png

·
·1 reply
Amy Shackles
Amy Shackles
Author
·Nov 25, 2020

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.

({}) > [] // true; ({}) < [] // false; ({}) == "[object Object]" // true

If you were to open a Node console rather than a browser console, you would see:

{} > [] // true; > {} < [] // false; {} == "[object Object]" // true

This is because Node made a change to evaluate input as expressions before evaluating them as statements. That change can be seen here.

·