DEV Community

Discussion on: Write better console.logs in JavaScript

Collapse
 
hume profile image
Horacio Rivero

I don't use console.log directly, I use the debbugger of devtools, if I have to log something, does through an abtraction.

I have a rule in eslint that does not allow me to use console.log.

Collapse
 
promikecoder2020 profile image
ProMikeCoder2020

Why comprehend using the debug for bigger logical bugs but for smalk fixes console.log is just more conveniet

Collapse
 
hume profile image
Horacio Rivero

There are several reasons, one of them is that the console log casts the data, forces the data to convert to another type to be able to display them on the screen, all the data is converted to a primitive String.

Another reason is that people often forget to remove the console.logs in various parts of their code.
Just open a debug tab on a web page and see how people forget to remove console.log in production.
Using console.log could be considered an anti-pattern that can turn into a big ball of mud.

Third reason it is very easy to use a debbuger nowadays.

There are many articles that talk about this topic.

Thread Thread
 
promikecoder2020 profile image
ProMikeCoder2020

Thanks for your detailed answer. But some points:

  • I think there is an option in some bundkers to remove console.logs and even if there isnt a global regex in replace and find should clean all of them.
  • To display objects and such you cpuld use something like console.table right? Which is nrarly the same thing