JavaScript console.log() Tutorial for Beginners

JavaScript is one of the most popular programming languages for web development. At WSNCode , we help beginners learn coding with simple and practical tutorials.

One of the first JavaScript functions every developer learns is console.log(). It is mainly used for printing messages, testing code, and debugging applications.

In this tutorial, you will learn how to use console.log() in JavaScript with simple examples.

What is console.log() in JavaScript?

The console.log() function is used to display messages in the browser console. Developers use it to check variable values, debug errors, and understand how code works.

Basic Syntax


console.log("Hello World");

When you run this code, the message will appear inside the browser developer console.

How to Open the Browser Console

  • Press F12 on your keyboard
  • Right-click the page and select Inspect
  • Open the Console tab

You can test JavaScript examples instantly using the WSNCode Editor .

Logging Variables

You can use console.log() to display variable values.


let name = "John";

console.log(name);

Output:


John

Logging Multiple Values

You can also print multiple values together.


let name = "Sarah";
let age = 22;

console.log(name, age);

Using console.log() for Debugging

Debugging helps developers find and fix problems in code. The console.log() function makes debugging easier.


let number = 10;

console.log("The value is:", number);

This method helps you track how your code behaves during execution.

Common Mistakes Beginners Make

  • Missing quotation marks
  • Typing Console.log() instead of console.log()
  • Forgetting parentheses
  • Using semicolons incorrectly

Learning these basics will improve your JavaScript skills quickly. Explore more beginner coding resources on WSNCode Explore .

Why console.log() is Important

The console.log() function is one of the most important debugging tools in JavaScript. Almost every developer uses it while building websites and applications.

It helps you:

  • Test code faster
  • Understand program flow
  • Debug errors easily
  • Check variable values instantly

Final Thoughts

Learning how to use console.log() is one of the first steps in becoming a JavaScript developer. It helps beginners understand how JavaScript works and makes debugging much easier.

At WSNCode , we regularly publish tutorials, coding examples, and web development guides to help developers improve their skills.

Explore more HTML, CSS, and JavaScript tutorials on WSNCode Explore .