In this tutorial, you will learn about the JavaScript console with the assistance of examples.
In this article, you will learn-
Description
The Console is one of the numerous Developer Tools available in web browsers. You can use the Console to debug or troubleshoot your JavaScript code. The area where you can find the Console will differ from browser to browser.
Steps to Open the Console Log in Google Chrome
JavaScript console.log()
All advanced browsers have a web console for troubleshooting. The console.log() technique is used to write messages to these consoles. For instance,
let sum = 44; console.log(sum); // 44
When you run the above code, 44 is printed on the console.
To learn more about using a console, visit: JavaScript Getting Started.
console.log() Syntax
Its syntax is:
console.log(message);
Here, the message refers to either a variable or a value.
Note: We will use the console.log() technique to show the output in our upcoming lessons.
Example 1: Print a Sentence
// program to print a sentence // passing string console.log("I love JS");
Output
I love JS
Example 2: Print Values Stored in Variables
// program to print variables values // storing values const greet = 'Hello'; const name = 'Salman'; console.log(greet + ' ' + name);
Output
Hello Salman
As should be obvious from these examples, console.log() makes it simpler to see the incentive inside a variable. That is the reason it’s usually used for testing/debugging code.
The console object also has various methods other than console.log(). To learn more, visit the JavaScript console.
Thanks for reading! We hope you found this tutorial helpful and we would love to hear your feedback in the Comments section below. And show us what you’ve learned by sharing your photos and creative projects with us.