Practically 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.
Maybe my debugger skills aren't strong enough, but I find that when I'm trying to reason about how some complicated code is executing, a debugger statement forces me to wade through tons of internals in libraries I don't care about. Some well-placed console logs give me much less information overload.
Advanced console.log Tips and Tricks (2020)
61–70 of 73 posts
Re: Advanced console.log Tips and Tricks (2020)
#62Not 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)
#63Earlier quoted context omitted.
You can also use monitor(func), debug(func) and inspect(func) and more :) https://developer.chrome.com/docs/devtools/console/utilities...
My favorites: - `$0` to refer to last selected DOM node - `copy(obj)` to copy something to clipboard (that might be hard to copy manually; for example long strings are often cut when selecting manually for copying)
Re: Advanced console.log Tips and Tricks (2020)
#64Earlier quoted context omitted.
You can also use monitor(func), debug(func) and inspect(func) and more :) https://developer.chrome.com/docs/devtools/console/utilities...
My favorites: - `$0` to refer to last selected DOM node - `copy(obj)` to copy something to clipboard (that might be hard to copy manually; for example long strings are often cut when selecting manually for copying)
Re: Advanced console.log Tips and Tricks (2020)
#65One 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.
Nonsense. Console.log does not accept a callback and does not return any promise, therefore it's expected to work synchronously.
Re: Advanced console.log Tips and Tricks (2020)
#66Practically 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)
#67If 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
DON'T YOU FEEL STUPID NOW?!
Re: Advanced console.log Tips and Tricks (2020)
#68One 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.
It was because one message was console.info and another was console.error, which was going to stderr and so getting flushed differently.
A couple months ago I fell for it again.
Re: Advanced console.log Tips and Tricks (2020)
#69Earlier quoted context omitted.
Nonsense. Console.log does not accept a callback and does not return any promise, therefore it's expected to work synchronously.
you're being ironic, right?
If JavaScript devs don't know if a function is async or sync it just gives more evidence that JS is a monkey-language. LOL!
Re: Advanced console.log Tips and Tricks (2020)
#70Not 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.
> javascript:(function(){console.log("monitor event"); window.addEventListener('message', (e) => {console.log(e);});})();
that way I can click the bookmark and start monitoring events whenever I want