JS Learning

JavaScript Basics

Lesson Progress0%

Section 4 of 4

Console Output

Console Output

Topic Overview

Take your time to understand each concept. Practice with the examples below!

The console is like a message board where your program can display information. It's incredibly useful for understanding what your code is doing!

console.log() is your main tool for printing messages:

  • Basic text output:
console.log("Hello World");
This prints: Hello World
  • Showing variable values:
let score = 100;
console.log(score);
This prints: 100
  • Combining text and variables:
let name = "Sarah";
console.log("Welcome,", name);
This prints: Welcome, Sarah
  • Using template literals (the modern way):
let age = 25;
console.log(`I am ${age} years old`);
This prints: I am 25 years old

Why use console.log()?

  • Check if your variables contain the right values
  • See if your code is running in the right order
  • Debug problems (find out where things go wrong)
  • Learn how JavaScript works by seeing results instantly!

Pro tip: You'll use console.log() constantly while learning - it's like having X-ray vision for your code!

Ready to practice? Try the exercise below to reinforce your learning!

Try it yourself

Create a variable with your favorite color and output it using console.log().

Loading...