Languages: [๐ช๐ธ] Espaรฑol - [๐บ๐ธ] English
Sometimes we need to console.log multiple variables and I've seen myself creating a console.log
with a previous title to identify the value and so on for each variable.
console.log("name: ", name);
console.log("age: ", age);
console.log("language: ", language);
console.log("isDev: ", isDev);
Hack
An easy quick way to get the same, without writing those previous titles is to put all variables inside an object {}
.
console.log( {name, age, language, isDev} );
But wait a moment. It can be better.
Super hack
Change .log
with .table
and voilรก. You will have a better view of all variable names and values.
console.table( {name, age, language, isDev} );
Bonus
There is an extension called Debug Snippets dedicated to debugging that includes a lot of console.log
combinations.
Two of those snippets are related to the hacks mentioned before.
Trigger | Description | Result JS/TS |
---|---|---|
cldโ |
log with destructuring | console.log({$name})โ |
ctdโ |
table with destructuring | console.table({$name})โ |
Thatโs All Folks!
Happy Coding ๐
Top comments (3)
Nice one boss ๐ ๐
Good one!
Nice trick, lemme take notes