What is the difference between console.log console.error?

Asked 2 years ago, Updated 2 years ago, 48 views

Especially when printing errors, I write console.log or console.error.

I learned the program on my own, so I wrote it confusedly without knowing the two meanings

There seems to be a strange difference, so I wonder exactly how you use it.

Thank you!

javascript angularjs

2022-09-22 21:40

2 Answers

What is displayed in the developer tool is different. The error appears as if it were an error, and it is also used in the developer tool to stand up and refer to the log only or to the error only. You can check it if you actually take a picture with Chrome developer tools.


2022-09-22 21:40

ko.wikipedia.org/wiki/ Standard_stream

Standard streams include stdin, stdout, and stderr console.log corresponds to stdout and console.error corresponds to stderr. The output on the screen is the same, but it's a completely different output.

In fact, for node.js, console.log is output as stdout and console.error as stderr.

With the following command:

node test.js 2> stderr.txt 1> stdout.txt

The contents of console.log(stdout) are only found in the file stdout.txt
The contents of console.error(stderr) can only be saved in a file called stderr.txt.


2022-09-22 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.