In this article, I am going to talk about Javascript Pro Tips. Please learn how to write solid modern Javascript and avoid bad code from the olden days.

Debugging

Actually it’s about console logging stuff.

How do you use console log? There are good ways and bad ways to console log. Imagine you have three different objects. Each one assigned to its own variable like this.

const foo = { name: 'tom', age: 30, nervous: false } 
const bar = { name: 'dick', age: 40, nervous: false }
const baz = { name: 'harry', age:50, nervous: false }

The obvious way to log these is just one after the other.

For example:

console.log(foo);
console.log(bar);
console.log(baz);

But the main problem is we don’t know the name of the variable when this gets logged but there’s a trick we can use here called computed property names where we add the variables to an object.

#coding #javascript #js #javascript-tips

Javascript Pro Tips
20.10 GEEK