It is possible to do:
let a = 1,
b = 3,
c = 9;
Is it also possible to do:
obj.a = 1,
b = 2,
c = 3;
This is still very readable, but a lot less typing, then writing obj a lot of times.
You can assign the defined variables using shorthand property names
let a = 1,
b = 3,
c = 9;
let obj = {a,b,c}
console.log(obj)
double memory usage huh?If there exists a relation between the property names and the values then one can write a compact object definition using map. Otherwise one can just initialize the object with names and values.
// function
var obj = {};
['a', 'b', 'c'].map((x, i) => (obj[x] = i));
console.log(obj);
// no function
var obj1 = {a: 1, b: 2, c: 4};
console.log(obj1);
Object.assign(obj, { a: 1, b: 2, c: 3 });would do it in 1 line, but just assigning 3 times in a row is not a bad thing