Earlier quoted context omitted.
console.log is not asynchronous. For example, this code: 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 s…
That's... what asynchronous means. The call to console.log() will return before the console output is actually produced.
Advanced console.log Tips and Tricks (2020)
41–50 of 73 posts
Re: Advanced console.log Tips and Tricks (2020)
#42const dog = { name: "Dog" }
console.log(dog) VM287:1 {name: "Dog"}
console.log({dog}) VM305:1 {dog: {…}}dog: {name: "Dog"}__proto__: Object
Re: Advanced console.log Tips and Tricks (2020)
#43Earlier quoted context omitted.
That's... what asynchronous means. The call to console.log() will return before the console output is actually produced.
To add to the MatthewMob's explanation, see this: https://imgur.com/a/vUTCumu
Re: Advanced console.log Tips and Tricks (2020)
#44Haven't seen this mentioned, but here's one: const dog = { name: "Dog" } console.log(dog) VM287:1 {name: "Dog"} console.log({dog}) VM305:1 {dog: {…}}dog: {name: "Dog"}__proto__: Object
Re: Advanced console.log Tips and Tricks (2020)
#45If 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
Re: Advanced console.log Tips and Tricks (2020)
#46Haven't seen this mentioned, but here's one: const dog = { name: "Dog" } console.log(dog) VM287:1 {name: "Dog"} console.log({dog}) VM305:1 {dog: {…}}dog: {name: "Dog"}__proto__: Object
What did you mean to emphasize here? Cos what I'm seeing is the language feature (ES6's "shorthand properties"), not something inherent to `console`.
EDIT: perhaps a better description by someone else https://news.ycombinator.com/item?id=27524164
Re: Advanced console.log Tips and Tricks (2020)
#47Practically 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)
#48A small extra trick: If you use arrow functions without a body you can log and fallback to the original statement. Example starting point, you're wondering what message is. ``` const upperCase = (message) => message.upperCase() ``` Don't add a body, just log and continue: ``` const upperCase = (message) => console.log(message) || message.upperCase() ```
Re: Advanced console.log Tips and Tricks (2020)
#49Practically 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.
console.log(JSON.stringify(myValue, null, 2)) could be what you are looking for.
Re: Advanced console.log Tips and Tricks (2020)
#50What 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.