Console warn()
Example
Write a warning to the console:
console.warn("This is a warning!");
Try it Yourself »
More examples below.
Definition and Usage
The warn()
method writes a warning to the console.
Note
When testing console methods, be sure to have the console view visible.
Press F12 to open the console veiw.
Syntax
console.warn(message)
Parameters
Parameter | Description |
message | Required. The message (warning) to write to the console. |
More Examples
Example
Use an object as the warning message:
const myObj = {firstname:"John", lastname:"Doe"};
console.warn(myObj);
Try it Yourself »
Example
Use an array as the warning message:
const myArr = ["Orange", "Banana", "Mango", "Kiwi"];
console.warn(myArr);
Try it Yourself »
Browser Support
console.warn()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 8-11 | Yes | Yes | Yes | Yes |