function addName(obj, name, value) {
return {...obj, name: value}
}
addName({}, "Brutus", 300)
When an object literal is created with a variable used as a key why is it that the variable doesn't get used? instead when the object is returned it just returns "name: 300" instead of "Brutus: 300". Interested just on this behavior, I understand the correct way to do this is to create an object separately and then create the key with the value (obj[name] = value).