console.error
Prints an error message — highlighted in red in the console.
Available since: Web API
Syntax
console.error(...values)Parameters
| Parameter | Type | Description |
|---|---|---|
| ...values | any | Values to print. |
Return value
undefinedReturns nothing.
Examples
An error message in catch:
try {
JSON.parse('{oops');
} catch (error) {
console.error('Could not load settings:', error.name);
}Output:
Could not load settings: SyntaxErrorNotes
In the browser such a message is shown in red and appears under the Errors filter. In Node.js it goes to the stderr stream, not the regular output.
See also
- console.warn — Prints a warning — highlighted in yellow in the console.
- console.log — Prints values to the console.
- try...catch — Catches errors so the program does not stop.
In the tutorial
- Debugging — How to find bugs in JavaScript: reading the error message, console.log and its variants, checking types, developer tools and debugger.