Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

console.warn

Prints a warning — highlighted in yellow in the console.

Available since: Web API

Syntax

console.warn(...values)

Parameters

ParameterTypeDescription
...valuesanyValues 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
connected

Notes

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.

Thanks for reading!

Donate to the site — we work hard for you.