Why doesn't this give me the object I expected .. which is {1:2} Instead the console gives {a:2}
function createObject (a, b) {
const myObject = {a:b}
console.log(myObject);
}
createObject(1, 2);
Why doesn't this give me the object I expected .. which is {1:2} Instead the console gives {a:2}
function createObject (a, b) {
const myObject = {a:b}
console.log(myObject);
}
createObject(1, 2);
Without brackets, the property name of a literal object is not evaluated as an expression:
function createObject (a, b) {
const myObject = {[a]: b}
console.log(myObject);
}
createObject(1, 2);