0

Consider below code

var myVariable = true;
var myObject = {myVariable};  // !! syntax of object creation !!
console.log(myObject);
console.log(myObject.myVariable);

Here is output

{ myVariable: true }
true

I have never saw the above syntax of Object creation. But it is working somehow. I didn't found any documentation station object creation in that way.

When I uglify this code. It will not work as desired

Is it good to create object like this?
Does all browser support this syntax?
Is there any documentation stating stating object creation in this way?

afzalex
  • 8,254
  • 2
  • 29
  • 53

0 Answers0