console.log
Outputs a message to the console at the log level
Syntax
console.log(...data)Parameters
| Parameter | Type | Description |
|---|---|---|
| data | any[] | Zero or more objects to output |
Return Value
undefined
Examples
console.log('Hello, world!');
console.log('Count:', 42);
console.log({ name: 'Alice', age: 30 });const items = [1, 2, 3];
console.log('Items:', items);
console.log('Length: %d', items.length);console.log('%c Styled text', 'color: blue; font-size: 20px;');Understanding console.log
The console.log method in JavaScript outputs a message to the console at the log level. It belongs to the console object and is one of the most widely used methods for working with console values in modern JavaScript and TypeScript applications.
The method signature is console.log(...data). It accepts 1 parameter: data. When called, it returns undefined. Understanding when and how to use log() helps you write more expressive, readable code.
Common use cases for console.log include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like console-error, console-warn, console-info, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for console.log is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
console.errorOutputs an error message to the console, typically styled differently from standard log messages
console.warnOutputs a warning message to the console
console.infoOutputs an informational message to the console
console.debugOutputs a debug message to the console, which is typically hidden by default in browser consoles
More Console Methods
Other methods in the Console object
Related Tools
More Console Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.