Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  71] [ 5]  / answers: 1 / hits: 79568  / 10 Years ago, wed, august 27, 2014, 12:00:00

What is the benefit of using console.log vs console.info?
Or any of the other console commands for that matter?



console.info(info);
console.error(error);
console.warn(warn);


vs



console.log(log);


I thought it might change the color of the output or concatenate some sort of label, but they seem to all do the same thing. And according to the documentation here:



https://nodejs.org/api/console.html#console_console_info_data



they seem to all do the same as console.log


More From » node.js

 Answers
9

According to the documentation that you linked to, console.error and console.warn output to stderr. The others output to stdout.


If you are doing piping or redirection from node.js the difference is important.


There is a lot of JavaScript written to run in both the browser and Node.js. Having node implement the full console allows for greater code cross-compatibility.


In most browsers, not only do these log in different colors, but you can also filter to see specific messages.




console.debug(debug); // Likely hidden by default
console.info(info);
console.error(error);
console.warn(warn);
console.log(log);




[#69636] Tuesday, August 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chelseyn

Total Points: 36
Total Questions: 85
Total Answers: 89

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;