JavaScript console.log() Method is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
Syntax:
console.log("");
Parameters:
It accepts a parameter that can be an array, an object, or any message.
Return value:
It returns the value of the parameter given.
These are the following ways to use the console.log() method:
Passing a number as an argument
If the number is passed to the function console.log() then the function will display it.
Example:
javascript
let a = 2;
console.log(a);
|
Output:
Passing a string as an argument
If the string is passed to the function console.log(), then the function will display it.
Example:
javascript
let str = "GeeksforGeeks" ;
console.log(str);
|
Output:
Passing a char as an argument
If the char is passed to the function console.log(), then the function will display it.
Example:
javascript
let ch = '2' ;
console.log(ch);
|
Output:
Passing a message as an argument
If the message is passed to the function console.log(), then the function will display the given message.
Example:
javascript
console.log( "GeeksforGeeks" );
|
Output:
Passing a function as an argument
If the function is passed to the function console.log(), then the function will display the value of the passed function.
Example:
javascript
function func() { return (5 * 19); }
console.log(func());
|
Output:

Passing a number with the message as an argument
If the number is passed to the function console.log(), then the function will display it along with the given message.
Example:
javascript
let a = 2;
console.log( "The value of a is " + a);
|
Output:

Passing a string with the message as an argument
If the string is passed to the function console.log(), then the function will display it along with the given message.
Example:
javascript
let str = "GeeksforGeeks" ;
console.log( "The value of str is " + str);
|
Output:
Passing a char with the message as an argument
If the char is passed to the function console.log(), then the function will display it along with the given message.
Example:
javascript
let ch = '2' ;
console.log( "The value of ch is " + ch);
|
Output:
Supported Browsers:
It is supported by all browsers.
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!