HTML DOM console.warn() method

Definition and usage

console.warn() The method writes a warning to the console.

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

instance

Example 1

Write a warning to the console:

console.warn("This is a warning!");

try it yourself

Example 2

Use an object as a warning message:

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

try it yourself

Example 3

Use an array as a warning message:

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

try it yourself

syntax

console.warn(message)

parameter value

parameter type description
message String or Object Required. The message or object written as a warning.

Browser Support

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

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