We use console.log to show messages or information on the screen while running JavaScript. It helps us see what the program is doing.
0
0
Output using console.log in Javascript
Introduction
To check the value of a variable while writing code.
To show simple messages or results to the user during development.
To debug and find errors by printing steps of the program.
To understand how data changes inside a program.
To quickly test small pieces of code in the browser or Node.js.
Syntax
Javascript
console.log(value1, value2, ..., valueN);
You can print one or many values separated by commas.
The values can be text, numbers, variables, or expressions.
Examples
Prints a simple text message.
Javascript
console.log('Hello, world!');
Prints the result of a math operation.
Javascript
console.log(5 + 3);
Prints a label and a variable value together.
Javascript
let name = 'Alice'; console.log('Name:', name);
Prints multiple values in one line.
Javascript
console.log('Sum:', 2 + 2, 'and product:', 2 * 3);
Sample Program
This program prints a welcome message, then shows the current age and the age next year.
Javascript
console.log('Welcome to JavaScript!'); let age = 25; console.log('Age is', age); console.log('Next year, age will be', age + 1);
OutputSuccess
Important Notes
console.log prints to the browser console or terminal, not on the webpage itself.
You can open the browser console by pressing F12 or right-click and choose 'Inspect' then go to the 'Console' tab.
Use console.log often to understand what your code is doing step-by-step.
Summary
console.log shows messages or values in the console.
It helps you see what your program is doing while it runs.
You can print text, numbers, variables, or many things at once.