DEV Community

Discussion on: Debugging - you’re doing it wrong. 10 techniques to find a bug in your code

Collapse
 
konstantinklima profile image
Konstantin Klima

I would just advise caution when doing console.log() on an object or an array objects you are tracking.
As i usually stick to backend languages, it really took me by surprise when I spent three hours basicly stripping several hundred lines of code in JS looking for a bug, just to realise that thr objects I was loging were printed out as they were at the end of execution and not in their current state for that current iteration as one would expect.
This was denoted by a little alert sign in chrome, which I checked out a bit too late. :D

An easy but boring workaround is to use JSON.stringify on the object when loging it. :)

Collapse
 
nikpoltoratsky profile image
Nik Poltoratsky

Thanks for sharing that tip. I've faced it multiple times and it still confuses me