Image for post
Image for post

JavaScript Developer Console

What your mother never told you ;-)

Ever seen the little info icon at the right of a console output and wondered what it means — like in the following example:

Image for post
Image for post

Position your mouse pointer above it and wait a second for the tooltip that says: “Value below was just evaluated now”.
What does that mean?

It simply says hey, what you will see here maybe is not the value you want to see here, because we look just now into the object and that could have been changed after the console log has been processed.

So if you really want the actual value at this point in code you should log it with JSON.stringify, otherwise you will get the latest value.

Image for post
Image for post

The example above simply illustrates this. I have expanded the object after I have changed the value of a.a to 2 and as expected it shows 2 for a.a.

Every now and than I use the above method to log objects to the console and as many times I wish the output would be pretty printed. And guess what, it is already there, because the method takes optional two arguments. The second optional one gives you the ability to set the spacing for the pretty printer.

So a call with 2 adds 2 spaces indent:

Image for post
Image for post

And it can even do more. With the first optional parameter you can change the output by replacing or omitting elements, but that’s another story.

MDN stringify

Developer since the 80'th, working at Forschungszentrum Jülich (http://www.fz-juelich.de) …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store