A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/node-js/node-js-console-error-function/ below:

Node.js console.error() Function - GeeksforGeeks

Node.js console.error() Function

Last Updated : 12 Jul, 2025

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
// Store number to variable
num = 20

// Check condition
if (num < 100) {
    console.log("Enter number greater than 100");
}
else {
    console.error("correct choice");
}        

Output: 

Enter number greater than 100

Program 2: 

javascript
// Store number to variable
x = 20;
y = 50;

// Check condition
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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4