Steps to Open the Console Log in Google Chrome
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.
Its syntax is:
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");
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);
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.
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.