0

While debugging some code, I came across something which looked like it shouldn't work. If I create a basic example in the Chrome console, it works too.

var id = 1;
var o = { id };
o;

This creates and prints the following object:

{ id: 1 }

Example:

enter image description here

What's going on here? The only question I can find with a similar syntax is this one:

JavaScript object literal syntax

...and the answers to that say it is just a code block, which clearly here it is not.

Whelkaholism
  • 1,413
  • 1
  • 17
  • 26

0 Answers0