...

/

Say “Hello” to the Browser

Say “Hello” to the Browser

Learn how to write your first JS code and send messages to the browser.

Welcome to the JavaScript course!

In this lesson, you’ll write your very first lines of code—and get the browser to respond. Instant feedback, no setup, just results.

Goals

You’ll learn to:

  • Write our first JavaScript commands.

  • Display messages using console.log() and alert().

  • See instant output in the browser.

Let’s talk to the browser

Press + to interact

JavaScript makes the web interactive. It all starts with simple commands—like this:

Printing a message to the console

This line tells the browser: "Say this in the console."

Notice how we’ve wrapped the text in double quotation marks. These quotation marks tell JavaScript that "Hello World" is a string—a sequence of characters meant to be read as text. The console.log() function then logs exactly what’s inside the quotation marks to the console.

Awesome—you just sent your first message to the browser!

Try a pop-up alert

Do you want your message to pop up right on the screen, like those little messages you sometimes see when visiting websites? Let’s try that now!

Showing a pop-up alert

For this, we use alert() instead:

A pop-up appears with your message!

This is hard to miss—it grabs attention, just like those alerts or confirmation boxes you’ve probably seen on websites. It’s a simple way to show important info while you’re learning JavaScript.

Try it yourself

Change the message to anything you want:

or

Make it personal. Celebrate your first line of code!

Just enough explanation

  • console.log() sends a message to the browser console.

  • alert() shows a pop-up message to the user.

  • Strings must go inside quotes: "like this" or 'like this'.

  • Every line ends with a semicolon ; (optional, but recommended).

Mini challenge

Try writing three messages ("Ready...", "Set...", "Go...")—one in the console, two as alerts:

If you’re stuck, click the “Show Solution” button.

You have already learned to sequence JavaScript commands.

What’s next?

Next, we will focus on modifying the content of a web page using JavaScript. You’ll learn how to select specific elements on the page using methods like getElementById() and how to update their content using properties such as .innerText. This will allow your website to respond visually to user actions — a key step toward making interactive, dynamic web experiences.