Use console.log() like a pro (2020)
31–40 of 156 posts
Re: Use console.log() like a pro (2020)
#32Another 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)
#33console.table O_O Wow, since when it was in JS?
https://developer.mozilla.org/en-US/docs/Web/API/Console/tab...
Re: Use console.log() like a pro (2020)
#34Not gonna lie, read this hoping to pat myself on the back for being a pro, twist: learned some cool stuff, console.memory()? Neato!
Re: Use console.log() like a pro (2020)
#35 console.log("some label: " + JSON.stringify(someObj))
pass it as a separate parameter: console.log("some label: ", someObj)
and you'll get interactive expansions/manipulation in the consoleRe: Use console.log() like a pro (2020)
#36Another 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.
Or you can console.log(JSON.stringify(x, null, 2));
Re: Use console.log() like a pro (2020)
#37Not gonna lie, read this hoping to pat myself on the back for being a pro, twist: learned some cool stuff, console.memory()? Neato!
Re: Use console.log() like a pro (2020)
#38Re: Use console.log() like a pro (2020)
#39Earlier quoted context omitted.
Unfortunately that tends to print the object with collapsed values, requiring you to expand the object to actually see any of the values.
I much prefer it being collapsed. When dealing with large objects, the firehose can be annoying.
Then you quit web development and start a new career.
Re: Use console.log() like a pro (2020)
#40Another 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.