In JavaScript, console is the object you use to print messages while a program runs. console.log("Saved") writes Saved to the browser’s DevTools console, or to the terminal when you run the same file in Node.js.
Logging is a side effect. The call prints the value and then returns undefined. Use log() for ordinary values, warn() when something looks wrong, and error() when a step failed. count() tells you how many times a line ran.
This page teaches what the console is. The Console Methods index lists every method in this JavaScript tutorial, including console.log(), console.table(), console.group(), and console.time().
The message is printed. The return value is undefined.
const result = console.log("Saved") prints Saved. result is undefined.
Syntax
JavaScript Syntax
Common console calls you will meet in a JavaScript tutorial:
console is a built-in object for messages you read while debugging. In a browser those messages appear in DevTools. In Node.js they appear in the terminal. console.log() is the method you will use first.
In Chrome, Firefox, or Edge, open DevTools and choose the Console panel (F12). The View Output boxes on this page show the same lines so you can follow the tutorial without leaving the page.
All three print a message. log() is for ordinary values, warn() is for something you should notice, and error() is for a failure. DevTools styles warn and error so they are easy to spot.
It returns undefined. The text you pass is printed as a side effect. If you write const result = console.log("Saved"), result is undefined and the console still shows Saved.
Practice the three examples here, then open the Console Methods index for log(), warn(), error(), table(), group(), time(), and the rest of the methods in this JavaScript tutorial.