console.log
Prints values to the console.
Available since: Web API
Syntax
console.log(...values)Parameters
| Parameter | Type | Description |
|---|---|---|
| ...values | any | Values to print; they are separated by spaces. |
Return value
undefinedReturns nothing.
Examples
Printing a value:
console.log('Hello, World!');Output:
Hello, World!Several values separated by commas:
const name = 'Anna';
const age = 25;
console.log('Name:', name, 'age:', age);Output:
Name: Anna age: 25A tip: the variable name next to its value:
const total = 42;
const user = 'Oleg';
console.log({ total, user });Output:
{
"total": 42,
"user": "Oleg"
}Notes
In the browser console objects and arrays can be expanded and inspected. On this site they are printed as JSON.
See also
- console.error — Prints an error message — highlighted in red in the console.
- console.table — Shows an array of objects as a table in the browser console.
- Template literal — A string in backticks with substitutions and line breaks.
Related recipes
In the tutorial
- Introduction to JavaScript — What JavaScript is, where it runs and what a first program looks like.