- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I print a message to the error console using JavaScript?
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.
Advertisements