Node.js console.log() Function

Last Updated : 3 Jun, 2026

The console.log() function in Node.js is a built-in method used to display output in the terminal, making it useful for checking values and following what happens as code runs.

  • Prints messages, variables, or expressions to the console.
  • Helps with debugging and quick testing during development.

Syntax

console.log([data][, ...additionalData]);

where,

  • data: primary value to be printed
  • additionalData: optional extra values, separated by commas, that will also be printed in the same line

This function contains multiple parameters that are to be printed.

Return type:Prints output to the console and returns undefined.

Example 1:

javascript
function GFG(name) {
     console.log("hello " + name);
}

// when parameters are passed
GFG("Geeksforgeeks");

Output:

Example 2:

javascript
function GFG(name) {
     console.log("hello " + name);
}

// No parameters are passed
GFG();

Output:

Use Cases

  • Debugging code: Helps identify issues by printing variable values and execution flow.
  • Tracking program execution: Useful for understanding which parts of the code are running.
  • Displaying results: Outputs computed values or function results to the terminal.
  • Inspecting data structures: Allows viewing objects, arrays, and JSON data during runtime.
  • Quick testing: Helps verify small code snippets without using a full debugger.
Comment

Explore