← Back
browser javascript things-i-learn

Log objects to console

TL;DR: expanded objects in the console shows state at current time, not when logged.

So, what you see might not be what you got.

What I mean... #

When writing object to the console using console.log the objects are contracted:

console.log

When the number of properties is too long, the contracted object is not complete (see the three dots ...)

console.log

You can expand an object in the console to see it:

console.log

But you can also change the object values (mutate the object, in FP jargon): console.log

And then expand 💥: console.log

As you can see, even if I logged the object before the mutation, when I expand, it shows the current (mutated) state. However the contracted version stays always the same.

When it matters... #

Always... but bear in mind that browser Event properties, for example, are mutated during the dispatch phase.