The console.error() function from the console class of Node.js is used to display an error message on the console. It prints to stderr with a newline.
Syntax:
console.error([data][, ...args])
Parameter: This function can contain multiple parameters. The first parameter is used for the primary message and other parameters are used for substitution values.
Return Value: The function returns an error message.
The below programs demonstrate the working of the console.error() function:
Program 1:
javascript
num = 20
if (num < 100) {
console.log( "Enter number greater than 100" );
}
else {
console.error( "correct choice" );
}
|
Output:
Enter number greater than 100
Program 2:
javascript
x = 20;
y = 50;
if (x > y) {
console.error( '%d is greater than %d' , x, y);
}
else {
console.error( '%d is less than or equal to %d' , x, y);
}
|
Output:
20 is less than or equal to 50
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
03 May, 2023
Like Article
Save Article