Looking at some videos about promises in node.js the guy uses console.error() to print things he know would error out and console.log() for everything else. Is there a main difference between these 2 functions besides printing things in distinct colours?
console. error is used to output error messages while console. log is the most commonly used console method and is used to log out all sorts of objects or messages. In case of some error browser automatically output the relevant error message while you have to manually log out objects using console.
The console. error() method outputs an error message to the Web console. Note: This feature is available in Web Workers.
The main purpose of the return value, is to use the function return value like you would have use a variable value. the console. log(); is a function (you can see the brackets) that will write the argument value on the console. And only the debuging console, in a browser you will not see anything on the screen.
print will just print the text to console. console. log() actually records it and we can use it for many purposes like email it for bug report.
console.error()
writes to stderr
, whereas console.log()
writes to stdout
as described in the doc.
In a default run of nodejs, both stdout
and stderr
go to the console, but obviously, they could be directed different places and could be used differently. For example, when using tools such as forever, the two streams are logged to separate log files so they can be examined separately.
The presumption is that console.error()
may contain more serious information that might want to be looked at separately, but that is really up to how you use console.log()
vs. console.error()
in your own program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With