JavaScript console.log() Method2 Mar 2025 | 3 min read The console.log() method is an essential method in JavaScript. It is utilized to print the output to the console. Syntax:Parameters: The console.log() method takes a parameter which can be any message, an object, array, etc. Return value: It returns a value which is given as a parameter. We can utilize the console.log() method in many ways:
Let us understand each one of them with the help of demonstrations. Giving a message as an argumentIf the message is given to the console.log() method as an argument then the message will be visible to the console. Demo: Output: We can witness the message visible to the console. Welcome to my website Giving a string as an argumentIf the string is given to the console.log() method as an argument then the string will be visible to the console. Demo: Output: We can witness the string to the console. Hello, how are you? Giving a char as an argumentIf the char is given to the console.log() method as an argument then the char will be visible to the console. Demo: Output: We can witness the character on the console. % Giving a number as an argumentIf the number is given to the console.log() method as an argument then the number will be visible to the console. Demo: Output: We can witness the number to the console. 10 Giving a string with the message as an argumentIf the string is given to the console.log() method as an argument then this method will show the string with the message. Demo: Output: We can witness the string with the message to the console. Hi dear, How are you? Giving a number with the message as an argumentIf the number is given to the console.log() method as an argument then this method will show the number with the message. Demo: Output: We can witness the number with a message to the console. The sum of a and b is 15 Giving a char with the message as an argumentIf the char is given to the console.log() method as an argument then this method will show the char with the message. Demo: Output: We can witness the char with a message to the console. The ampersand symbol looks like this: & Giving a function as an argumentIf the function is given to the console.log() method as an argument then this method will show the value of the given function. Demo: Output: We can witness the value of the function to the console. 109 Giving an object as an argumentIf the object is given to the console.log() method as an argument then this method will show the object to the console. Demo: Output: We can witness the object to the console. Giving an array as an argumentIf the array is given to the console.log() method as an argument then this method will demonstrate the array to the console. Demo: Output: We can witness the object to the console. Following are the browsers that support the console.log() method:
Conclusion:We have studied the JavaScript console.log() method in this article. With the help of demonstrations, we have comprehended many ways to utilize the console.log() method. |
Because it lets builders create dynamic, interactive, and responsive user reports, JavaScript has grown to be a critical aspect of cutting-edge web development. Knowing whilst to govern the Document Object Model (DOM) is an essential part of running with JavaScript. The timing of a website's accessibility...
6 min read
We will comprehend how to convert a number to a string in JavaScript in this article. There are many methods that we can utilize to convert a number to string in JavaScript which are as follows: Utilizing the toString() Method Utilizing the String() function Concatenating an Empty String Utilizing the...
3 min read
An API allowing developers to view file data asynchronously is called JavaScript FileReader. The filereader offers several file-reading methods. It includes readAsArrayBuffer() and readAsText(); a load event is triggered when a file is read. The createObjectURL() method of the FileReader Library enables developers to create...
6 min read
What is OnKeydown? In JavaScript, Onkeydown is an event handler that can be called when a person presses the key on the keyboard. We can use any of the elements when we use the web element where a person can input characters into a form element...
6 min read
When it comes to web development, HTML, CSS, and JavaScript are the three most important languages. Having the correct Integrated Development Environment (IDE) may greatly increase productivity and optimize your workflow, regardless of the complexity of the web application you're developing or the simple webpage...
8 min read
What is Filter in JavaScript? In JavaScript, a filter is a method for arrays that allows you to create a new array containing only elements that pass a certain condition. It doesn't modify the original array instead it returns a new array with elements that satisfy the...
7 min read
Being a scripting language, sometimes the JavaScript code displays the correct result even it has some errors. To overcome this problem we can use the JavaScript strict mode. The JavaScript provides "use strict"; expression to enable the strict mode. If there is any silent error or...
1 min read
The regex "\b" shows the available start or end of the character in the input string in JavaScript. The regex "\b" shows the character's unavailable start or end in the JavaScript input string. We can test, search, and match the arability of the required character...
5 min read
In this article, we are going to discuss JavaScript's in operator. We have heard and discussed many times about arithmetic, logical, comparison, and other operators. But have you heard or know about the in operator of JavaScript. Probably the answer is no, so let's discuss...
3 min read
What is ? In JavaScript, the triple-equal operator tests for strict equality. The triple equals will not do the type conversion if there are two values that are not of the same type comparison. In the case of "===," it will return false. It means that the...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India