+ 2

Why is this showing I am not defined ?

const obj1 = {name: kashyap}; const obj2 = {age: 120}; const tar = Object.assign({}, obj1, obj2); console.log(tar); // kashyap is not defined

24th Sep 2020, 2:47 PM
Kashyap Kumar
Kashyap Kumar - avatar
2 Antworten
+ 5
{name: "kashyap"} You need those quotes, otherwise it will search for a variable with the same name
24th Sep 2020, 2:53 PM
Bagon
Bagon - avatar
+ 3
It should be a String. const obj1 = {name: 'kashyap'};
24th Sep 2020, 2:52 PM
Avinesh
Avinesh - avatar