What’s the Output? JavaScript Object Reference
Let’s solve an object reference puzzle. What do you think the output will be?
const obj1 = { a: 1 };
const obj2 = obj1;
obj2.a = 2;
console.log(obj1.a); // Output?
Explanation:
Both obj1 and obj2 reference the same object in memory. Modifying obj2.a also changes obj1.a, so the output is 2.
#coding
#javascriptframework
#javascript
#javascripttutorial
#inputoutput
コメント