Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js console.error() Function

  • Last Updated : 14 Oct, 2021

The console.error() function from console class of Node.js is used to display an error messages on the console. It prints to stderr with newline.
Syntax: 

console.error([data][, ...args])

Parameter: This function can contains 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.
Below programs demonstrates the working of console.error() function:
Program 1: 

javascript




// Store number to variable
num = 20
  
// Check condition
if (num < 100) {
    console.log("Enter number greater then 100");
}
else {
    console.error("correct choice");
}        

Output: 

Enter number greater then 100

Program 2: 

javascript




// Store number to variable
x = 20;
y = 50;
  
// Check condition
if (x > y) {
    console.error('%d is greater then %d', x, y);
}
else {
    console.error('%d is less then or equal to %d', x, y);
}

Output: 

20 is less then or equal to 50

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!