0

var obj = {
  b: 2
};
console.log(obj.a);
console.log(obj);
obj.a = 1;
console.log(obj);

The three console.log() outputs the following results:

img1

The first undefined I can understand, but the second one can output a:1, and it can be seen that the second and third printing results have a distinct difference:

Why has the first parenthesis only b:2, and the second full output?

clemens
  • 16,716
  • 11
  • 50
  • 65
Wen Sun
  • 1
  • 1
  • 1
    As you can see, the console-output is not as you stated. – Esko Jan 19 '18 at 06:06
  • *"Why has the first parenthesis only b:2, and the second full output?"* Because at the moment you are logging the object the first time, it only has a single property. When you log it a second time it has two properties. – Felix Kling Jan 19 '18 at 06:11
  • 1
    Expanding the object in the console shows the state of the object at the time you expanded it. – JLRishe Jan 19 '18 at 06:11
  • @Wen-Sun Check the blue i tooltip. The values are updated by not the header. – kiranvj Jan 19 '18 at 06:15

0 Answers0