DEV Community

loading...
Cover image for console.log() hack for debugging

console.log() hack for debugging

equiman profile image Camilo Martinez ・1 min read

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);
Enter fullscreen mode Exit fullscreen mode

console.log

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} );
Enter fullscreen mode Exit fullscreen mode

console.log

But wait a moment. It can be better.

Super hack

Change .log with .tableand voilá. You will have a better view of all variable names and values.

   console.table( {name, age, language, isDev} );
Enter fullscreen mode Exit fullscreen mode

console.table


That’s All Folks!
Happy Coding 🖖

Buy me a cofee

Discussion

pic
Editor guide
Collapse
baharajr profile image
Bennett(he/him)

Nice one boss 👏 👏

Collapse
dmcantero profile image
dmcantero

Good one!

Collapse
ptprashanttripathi profile image
Pt. Prashant tripathi

Nice trick, lemme take notes