0

Please share your thoughts regarding below outputs.

var a = '';
console.log(a); //this logs nothing as expected.
a = 'triven';

first log

var a = {};
console.log(a); // How javascript is aware of property here that is defined below. 
a.name = 'triven';

enter image description here

Triven
  • 351
  • 1
  • 4
  • 17

1 Answers1

0

I think you're looking for console.dir().

console.log() doesn't do what you want because it prints a reference to the object, and by the time you pop it open, it's changed. console.dir prints a directory of the properties in the object at the time you call it.

The JSON idea below is a good one; you could even go on to parse the JSON string and get a browsable object like what .dir() would give you:

console.log(JSON.parse(JSON.stringify(obj)));

PSN
  • 2,326
  • 3
  • 27
  • 52