Say Hello to the Browser
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.
Goal
You’ll aim to:
Write your first JavaScript commands.
Display messages using
console.log()
andalert()
.See instant output in the browser.
Talk to the browser
JavaScript is how we make the web do things. And it starts with just talking—like this:
Printing a message to the console
That 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
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.
Explanation
console.log()
= Send a message to the browser console.alert()
= Show 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).
Let’s practice
Now, let’s lock in what you’ve just learned with a quick quiz in the next lesson to help you reinforce your understanding before we move on.