What is {x:1} and why does it return 1

Adding semicolon at the end bypasses the Chrome regex. Which is kinda meh since these two obviously have the same effect:

a = {x:1}

a = {x:1};

Then, I was bored enough to toy in console with a few more variations of the theme on both Chrome and FF.

{x:1} // Chrome returns an object, FF 1

{x:1}; // Chrome and FF return 1

{x:1;} // Chrome and FF return 1

{x:1,} // Chrome returns an object, FF throws a syntax error

({x:1,}) // Both return an object

{x:1} == {x:1} // Chrome says false (passes the regex), FF says syntax error

{x:1} == {x:1}; // Now both agree on syntax error

({x:1} == {x:1}) // Now both agree on false

Author: Shantun Parmar

Comments are closed.