Earlier quoted context omitted.
I much prefer it being collapsed. When dealing with large objects, the firehose can be annoying.
Then, one day, after 12 hours chasing a race condition bug, you learn that when you expand objects from console.log, it shows you the current value of properties and not the values at the time of the console log. Because the values are evaluated when you click on the arrow. Then you quit web development and start a new career.
Use console.log() like a pro (2020)
91–100 of 156 posts
Re: Use console.log() like a pro (2020)
#92I think the very fact that you have to rely on things like that when debugging speaks volumes about the language deficiencies. Or maybe it's just the tooling or environments where JS is executed? In any case, the debugging experience is probably the biggest reason why I dislike modern web dev and tend to steer my career towards back-end.
Re: Use console.log() like a pro (2020)
#93Another little trick; instead of doing: 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 console
No, this is totally different. In the second version, if someObj changes after it was logged, when you'll expand it you'll see the updated value. JSON.stringify freezes the value. To get the same as the first example, but interactive, you have to do: console.log("some label: " + JSON.parse(JSON.stringify(someObj)))
Re: Use console.log() like a pro (2020)
#94I've put over 200 tips like that on my website: https://umaar.com/dev-tips/ Each tip has a textual explanation, and an animated gif if you're a visual learner (I know, I need to scrap gifs and move to regular videos). There's a lot of tricks there which can hopefully improve your development and debugging workflows. Let me know if there are specific things you'd like to see. A few people have asked for how to find me…
Re: Use console.log() like a pro (2020)
#95Re: Use console.log() like a pro (2020)
#96Re: Use console.log() like a pro (2020)
#97I think the very fact that you have to rely on things like that when debugging speaks volumes about the language deficiencies. Or maybe it's just the tooling or environments where JS is executed? In any case, the debugging experience is probably the biggest reason why I dislike modern web dev and tend to steer my career towards back-end.
A language/runtime/framework gives you options and you pick your poison, browsers offer you step by step debuggers and REPL out of the box and I actually think it's awesome in terms of debugging, you can of course only use console.log(), and it's a good place to start. When you're ready to move on there are many more useful tabs in the browser devtools to debug with.
Re: Use console.log() like a pro (2020)
#98Very important for backend is %j (e.g.: console.log('%j', variable); which can output complex json objects to the terminal. I often write it to the terminal and then copy it to an online json viewer so it is formatted in a viewable format.
Maybe you can skip a step with pasting online.
Re: Use console.log() like a pro (2020)
#99This for example will call `console.log(myVar)` and still call `someFunction(myVar, someOtherArgument)`.
myVar = "12345"
someFunction((console.log(myVar), myVar), someOtherArgument);
Pretty handy sometimes :)Re: Use console.log() like a pro (2020)
#100for what its worth i have this guy blocked on twitter - all he does is repost basic APIs you can get from MDN. classic grift playbook.
I don't think closing on people just starting to learn is a good way to expand the field of software engineering.