How can I print a message to the error console, preferably including a variable?

For example, something like:

print('x=%d', x);

18 Answers
18

console.error(message); // Outputs an error message to the Web Console
console.log(message); // Outputs a message to the Web Console
console.warn(message); // Outputs a warning message to the Web Console
console.info(message); // Outputs an informational message to the Web Console. In some browsers it shows a small "i" in front of the message.

You also can add CSS:

console.log('%c My message here', "background: blue; color: white; padding-left:10px;");

More info can be found here: https://developer.mozilla.org/en-US/docs/Web/API/console

Leave a Reply

Your email address will not be published. Required fields are marked *