0

I am experiencing a weird behavior while logging an object to the console.

I have a js class "Attribute". That class has an attribute "value". I had some problems with my code, so i decided to log the content to the console.

The funny thing is, when i log the object of the Attribute class to the console,

console.log(myAttribute)

it shows me this:

{ value: NaN }

But when i log the attribute directly,

console.log(myAttribute.value)

It shows me the correct value

"asd23gq"

That happens on Chrome and on Firefox. I have no way of explaining the behavior. Has anyone experienced something similar?

  • 1
    Can you show the code you're using to set `myAttribute`? – Jamie Barker May 05 '15 at 09:06
  • share the implementation of the attribute 'class' – ztadic91 May 05 '15 at 09:10
  • The most likely culprit is that you modify the object `myAttribute` after the `console.log()`. Most `console.log()` implementations will print values *after* your current javascript code is done executing(e.g. see http://stackoverflow.com/questions/10040856/synchronous-console-logging-in-chrome). But what you should actually do is use the debuggers present in both Chrome and Firefox - https://developer.chrome.com/devtools/docs/javascript-debugging – Sacho May 05 '15 at 09:16
  • Well at first this is a simple assignment of a text. Later on, I found a parseInt(value) - That would explain the NaN value. But that happens after the logging ... – user4865579 May 05 '15 at 09:24

0 Answers0