Consider the following example
var x = 1;
var obj = {y:1, x};
console.log(obj, obj.x);
I have tried to find many stackoverflow posts and MDN documentations, but I fail to find any reference that says we can use variables as object keys without the ES6 array syntax. That is, I assume js allows var x=1; var obj2 = {y:1, [x]: 3}
.
Is there some sort of object destructuring happening? Why can I use a variable as property name in the object literal creation without even assigning that property a value?