Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

console.log is not a good substitute for dd #2

Closed
hackel opened this issue Oct 18, 2017 · 2 comments
Closed

console.log is not a good substitute for dd #2

hackel opened this issue Oct 18, 2017 · 2 comments

Comments

@hackel
Copy link

hackel commented Oct 18, 2017

As I'm sure you know, console.log doesn't print a snapshot of the variable at that time, which means that later code can change the result when you expand objects in a browser. I've seen various solutions to this, such as JSON.parse(JSON.stringify(value)), and I won't claim what is the best, but a proper dump function should definitely print objects exactly as they are at that moment in time.

@ovanschie
Copy link
Member

I don't understand why console log wouldn't print a snapshot. You are logging the value at the time of logging right?

@hackel
Copy link
Author

hackel commented Nov 10, 2017

Because you're just passing a reference to an object to console.log. The reference itself does not change, however the browser will not evaluate the contents of the object until it is actually expanded, at which point its contents may have changed. This is a pretty common Javascript debugging issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants