What is the benefit of using console.log
vs console.info
?
Or any of the other console commands for that matter?
console.info(\"info\")
The different logging levels let you manage the noise level in your console: In both the Firefox (I'm using 78 right now) and Chrome (84) devtools, the js console lets you choose what "debug level" of output you want to see. FF lets you toggle the visibility of console.error
, .warn
, .log
, .info
, and .debug
messages by clicking individual buttons for each (that show you how many were suppressed, when "off"), whereas Chrome has a dropdown with checkmarks next to the items (.info
and .log
are controlled by the "Info" one, and .debug
by "Verbose"). The Chrome dropdown label ("All levels" or whatever you set) turns red if output was suppressed.
While console.log
and console.info
might not be different, there are other uses except mere coloring. For example, when using a linter like eslint, you can set console.log
to provide a warning message. Let's say you only want to use console.log
for your development purposes and use console.info
for information that end users might need. With a linter you now have a visible and direct reminder of your temporary console.log
that aid you during development, but must be removed before commits/publishing.
console.log()
is shorter than console.info()
They're the same thing, and that's the only advantage.
Visually, No difference actually among console.log
, console.info
, console.warn
, as well as console.error
regarding the server side(terminal).
However, there are lightweight modules that add blue, orange and red colors for console.info
, console.warn
, as well as console.error
respectively . By that, console API behaves like client-side.
npm i console-info console-warn console-error --save-dev;