In this section, we will learn what the console error() method is and how to use it in JavaScript.
JavaScript Console error() Method
The `error()` method is a way of sending error messages to browsers console. The difference between messages sent via this method and other methods like `log()` is on their appearances on the console!
Basically, a message that is sent via the error() method will appear in a red box with an alarm signal so that users know this is an error.
Console error() Method Syntax:
console.error(message)
Console error() Method Parameter:
The method takes one or more arguments and those are the messages or objects that we want them to be sent as an error to the console.
Console error() Method Return Value:
This method does not return a value.
Example: how to log JavaScript errors
console.error("Anonymous error occurred!"); console.error({name:"John",lastName: "Doe"});
Output:
Anonymous error occurred! {name: "John", lastName: "Doe"}
Note: if you open the browser console, you’ll see these messages are in a red block to visually signal users that they are dealing with an error.