If it's not on all the browsers, please don't use any of this shit. Every time you use a chrome-specific browser you encourage the eventual death of all the non-chromium browsers which might be great for you right now, but is bad for the ecosystem in the long term. Also, please stop writing tech blogs on medium. That well paid tech people of all people would be constrained to a paywall-middleman is an indictment of o…
All the shit is cross-browser supported
Advanced console.log Tips and Tricks (2020)
21–30 of 73 posts
Re: Advanced console.log Tips and Tricks (2020)
#22My dumb dead-simple trick that you've probably independently invented yourself: when I want to log variables x,y,z I write console.log({x,y,z}) not console.log(x,y,z) Who needs pretty-printing, formatting libraries, string interpolation etc?
Re: Advanced console.log Tips and Tricks (2020)
#23If the objects to be printed change between console.log() and the actual printing, the output you see may not represent the state when console.log() was called.
Re: Advanced console.log Tips and Tricks (2020)
#24What pains me that browsers no longer put blue icon with console.info. Like, what's the point of having it if it's going be virtually indistinguishable from .log? It annoying.
I take advantage of this so that my .log lines are stuff I need while developing but they shouldn't get committed, that's what the actual named log lines are for.
Re: Advanced console.log Tips and Tricks (2020)
#25"upgrade to see more" paywalled story...
Re: Advanced console.log Tips and Tricks (2020)
#26Practically every time I do a 'console.log' to see the value of something in the current page state I actually wanted a 'debugger' statement instead. Pausing execution so I can look at other things around what I wanted to log often proves very useful and let's me get to the root cause of a problem faster.
Re: Advanced console.log Tips and Tricks (2020)
#27One thing to watch out is that console.log is asynchronous. If the objects to be printed change between console.log() and the actual printing, the output you see may not represent the state when console.log() was called.
Re: Advanced console.log Tips and Tricks (2020)
#28One thing to watch out is that console.log is asynchronous. If the objects to be printed change between console.log() and the actual printing, the output you see may not represent the state when console.log() was called.
let a = "hello";
console.log( a );
let a = "goodbye";
will always reliably print "hello", not "goodbye".What you're referring to is the fact that when you expand an object or array in the console, then you see the contents of that object or array at the time you expand it, not as it originally existed when console.log() was called.
This is why alessioalex's sibling comment is so useful. By logging the output from JSON.stringify(), you are logging a string whose value will not change.
Re: Advanced console.log Tips and Tricks (2020)
#29Not directly console.log related, but you can use the console-only monitorEvents() method to log all the events triggered on an element: https://developers.google.com/web/updates/2015/05/quickly-mo... Very useful when you are wiring events together on the front end. Surprised there isn’t a standard way to do this in the DOM.
Re: Advanced console.log Tips and Tricks (2020)
#30This is solved by separating out your log library into a separate file, and then blackboxing it. Voila, original call points are preserved making debugging easier and your logs more useful.