Node.js | console.warn() Function

The console.warn() function from console class of Node.js is used to display the warning messages on the console. It prints to stderr with newline.

Note: This function is an alias of console.error() function.

Syntax:



console.warn( [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 the warning message.

Below programs demonstrate the working of the console.warn() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

function displayWarning(x) {
    console.warn(`GeeksforGeeks is a ${x} portal`);
}
   
const x = 'Computer Science';
  
displayWarning(x);

chevron_right


Output:

GeeksforGeeks is a Computer Science portal

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

function compareNumber(x, y) {
      
    // Check condition
    if (x > y) {
        console.warn(`${x} is greater then ${y}`);
    }
    else {
        console.warn(`${x} is less then or equal to ${y}`);
    }
}
  
// Store number to variable
x = 100;
y = 50;
  
compareNumber(x, y);

chevron_right


Output:

100 is greater then 50


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.