Skip to content
Advertisement

Display yellow warning message in console

I want to show a warning message in the Chrome console, like the highlighted item in this screenshot:

The message has a pale, yellow background with brown text and is prefaced with a yellow warning triangle.

console.log(message) displays a normal white message.

console.error(message) creates an error message.

But using console.warning(message) returns Uncaught TypeError: console.warning is not a function.

So is there any way to present a console warning for JavaScript?

It should be like this:

JavaScript
JavaScript
JavaScript

But it doesn’t work. How do I do this?

Edit: I could use custom CSS!

JavaScript

But it just doesn’t look right:
failed attempt

Advertisement

Answer

Try using console.warn method instead of console.warning.

Example

JavaScript

Reference

Here’s a resource containing a full list of available console methods: https://developer.mozilla.org/en-US/docs/Web/API/console#methods

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement