HTML DOM console.error() method

Definition and usage

The console.error() method writes error messages to the console.

The console is very useful for testing.

Tip:When testing this method, make sure the console view is visible (press F12 to view the console).

Instance

Example 1

Write to the console:

console.error("You made a mistake");

Try it yourself

Example 2

Use an object as an error message:

var myObj = { firstname : "Bill", lastname : "Gates" };
console.error(myObj);

Try it yourself

Example 3

Use an array as an error message:

var myArr = ["Orange", "Banana", "Mango", "Kiwi" ];
console.error(myArr);

Try it yourself

Syntax

console.error(message)

Parameter value

Parameter Type Description
message String or Object Required. As an error message or object to be written.

Browser Support

The numbers in the table indicate the first browser version that fully supports this method.

Method Chrome IE Firefox Safari Opera
console.error() Support 8.0 4.0 Support Support