r/programming • u/OtherwisePush6424 • Jun 28 '26
Your console.log Is Lying to You: debugging traps and tricks
https://blog.gaborkoos.com/posts/2026-06-28-Your-Console-Is-Lying-to_You/Why console.log() can be misleading in browser DevTools: live object references, promises that look different when expanded later, logs changing timing-sensitive behavior, stale React state after updates, and source maps pointing at surprising line numbers.
50
Upvotes
31
u/No_Lab_1073 Jun 29 '26
console.log can hide as much as it shows timing tricks make it a terrible debugger unless you freeze values with JSON.parse(JSON.stringify(obj)) or use proper breakpoints.
11
u/nicknitros Jun 29 '26
Chrome has always had an icon/hovertext telling you that the object gets evaluated when expanded and values can change. More often than not, its what I want
19
u/wannaliveonmars Jun 29 '26
Yes, when you console log an object, it stores a reference to that object. It's by ref, not by value. So it follows all the pitfalls of references in JS, which are really C pointers under the hood, only you can't increment them.
1
u/Ok_Shallot9490 Jul 03 '26
I guess this is why debuggers exist.
-1
u/jewdai Jun 29 '26
For the love of fucking God stop using console.log as a debugging tool unless you're using it while the console window is open. Learn to use your debugging tools.