Live data from Hacker News

Use console.log() like a pro (2020)

markodenic.com

11–20 of 156 posts

Re: Use console.log() like a pro (2020)

#15
post #2

Another trick that might be more practical for actually debugging is using the object shorthand. For example, instead of... console.log(x, y); which contains the information you need, but lacks any useful context, try... console.log({x, y}); ...which will print out like an object, including the key names.

Unfortunately that tends to print the object with collapsed values, requiring you to expand the object to actually see any of the values.

Re: Use console.log() like a pro (2020)

#16
post #2

Another trick that might be more practical for actually debugging is using the object shorthand. For example, instead of... console.log(x, y); which contains the information you need, but lacks any useful context, try... console.log({x, y}); ...which will print out like an object, including the key names.

thank you. hadn't seen that before

Re: Use console.log() like a pro (2020)

#18
Let me save someone a few minutes of confusion: generally I use console.table instead of console.dir ever since I discovered console.dir is basically unpredictable. Try using it on an Error or anything that inherits from Error and you'll see it puts out what looks like an expandable stack trace. I have no idea how or why it's implemented to do that, but basically it just varies from one object to the next and I dislike that.
Post reply on HN