How do I print a message to the error console using JavaScript?

JavascriptWeb DevelopmentFront End Technology

To print a message to the error console, use the console object. Here’s an example −

The following will show a red error message −

console.error(message);

The following gives you the default message −

console.log(message);

The following gives you the warning message −

console.warn(message);

The following gives an information message −

console.info(message);

Add CSS to the log message −

console.log('%c Add message!, "background: green; color: white;");

Use the following to print error. Consider “num” as the variable name −

console.error('num=%d', num);

For complete API reference, refer Console API Reference.

raja
Ali
Published on 01-Feb-2018 16:19:06
Advertisements