JavaScript console error() method is “used to write an error message to the console.” It outputs an error message to the Web console.
Syntax
console.error(message)
Parameters
message: The error message to write to the console.
Return Value
None.
Example 1: How to Use console.error() Method
If you are working with a webpage, then this is your code.
<script>
console.error("You had a mistake and now in console.error()");
</script>
Output
If you are working in Node.js, then you should write your code like this:
console.error("You had a mistake and now in console.error()");
Output
You had a mistake and now in console.error()
Example 2: Using an object as the error message
const obj = {name: "KB", rollno: 19};
console.error(obj);
Output
{ name: 'KB', rollno: 19 }
Example 3: Using an array as the error message
const arr = ["BMW", "Audi", "Mercedez"];
console.error(arr);
Output
[ 'BMW', 'Audi', 'Mercedez' ]
Browser compatibility
The console.error() method is supported in all browsers and Node.js.
That’s it!

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.