0

In the screenshot below you will see a console.log print of an object that has a theme field. But this field at the same time has and doesn't have a value. How to interpret this? My intent is to assign the value. enter image description here

ps0604
  • 1,227
  • 23
  • 133
  • 330

3 Answers3

1

When a property is filled asynchronously, or parent object is console logged before it's property is filled with value, such the behaviour will occur.

var obj = {};

// here when checking the dev tools obj = {}

ajax('url', function() {
 obj.a = 5
 // here when checking the dev tools obj = { a : 5}
})
Oskar Szura
  • 2,469
  • 5
  • 32
  • 42
1

Logging objects in Chrome is a bit tricky. If you do a log of the entire object and then change a property of the object, it always shows the latest value for the property.

Try logging Object.theme instead of logging the entire object and you will see the difference.

  • I understand that Chrome may change the object with the new value, but that doesn't explain why I have two different values. – ps0604 Jul 15 '16 at 11:30
0

There is small blue icon on your screenshot, hover it and you get the answer to your question.

Maxx
  • 1,740
  • 10
  • 17