Today I saw a piece of code that I had never seen before:
var a = 1;
var b = 2;
var c = { a, b };
This creates an object (assigned by c) that contains two keys, these are the names of the variables, and the values are the values of the variables, for example:
{
a: 1,
b: 2
}
Is this something normal? I could not find anything related to this or creating objects this way. I tested it on chrome and it worked fine, but I'm not sure if this will work in every browser.
I would like to create an object this way:
var c = { a: a, b: b };
source
share