0

In my JS script (inside a simple html page) I have an Object which I print with console.log(subs). In Dev Console I see that subs is:

> Object { topic: "hgm_giuse/#", qos: 2 }

But If click on the arrow on the left to expand the object I see this:

{…}​
  qos: 128​
  topic: "hgm_giuse/#"​
  <prototype>: Object { … }

Whre that "128" comes from?

gdm
  • 7,647
  • 3
  • 41
  • 71
  • 1
    Look at @zzzzBov answer to see if it helps you https://stackoverflow.com/questions/23429203/weird-behavior-with-objects-console-log. Fast resume : console.log display the state of the object right know. when you use the expand arrows, it load the object value dynamically. So between the first log and the expand log, the object may have been modified and changed of value. – Orelsanpls Sep 14 '18 at 15:21
  • may be you're seeing the another object that looks alike that but `qos` is 128 – A l w a y s S u n n y Sep 14 '18 at 15:21
  • 1
    Possible duplicate of [Weird behavior with objects & console.log](https://stackoverflow.com/questions/23429203/weird-behavior-with-objects-console-log) – Andreas Sep 14 '18 at 15:25
  • Use `JSON.parse(JSON.stringify(yourObject));` if you want to have a "real time" value of the object (when printed). Otherwise, the browser will automatically evaluate the latest value of it (in chrome, you can see a little "i" info label next to the object: hovering it you will see that the label explains the value is being evaluated just now). – briosheje Sep 14 '18 at 15:49

1 Answers1

1

The object just got modified after the first console.log!

You can reproduce it in the dev tools console:

a = {b: 12}
console.log(a) -> {b: 12}
a.b = 24;
console.log(a) -> {b: 24}

When you now expand the first logged out object, it will also show 24 since it is just a reference to a :-)

Achim
  • 101
  • 1
  • 4