console.warn
Prints a warning — highlighted in yellow in the console.
Available since: Web API
Syntax
console.warn(...values)Parameters
| Parameter | Type | Description |
|---|---|---|
| ...values | any | Values to print. |
Return value
undefinedReturns nothing.
Examples
A warning about a deprecated option:
function connect(options) {
if (options.legacy) {
console.warn('The legacy option is deprecated');
}
return 'connected';
}
console.log(connect({ legacy: true }));Output:
The legacy option is deprecated
connectedNotes
Warnings can be filtered in the console separately from regular messages and errors.
See also
- console.error — Prints an error message — highlighted in red in the console.
- console.info — Prints an informational message.
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.