Answered Plainly

Learning JavaScript โ€” First Steps for Kids

JavaScript is the programming language of web pages. MDN โ€” the big free library of web lessons โ€” says it adds interactivity to a website: games, answers when buttons are pressed, moving pictures, and pages that change while you look at them. HTML builds the page. JavaScript makes the page answer back.

On this page you will copy one small, real program. It makes a web page with a button. When you click the button, the page's big heading changes its words. Every line of the program is a pattern from MDN's own first JavaScript lesson.

Pick your grade:

Elementary: A Page That Answers Back

JavaScript lives in your browser

You do not need to install anything. JavaScript already lives inside every web browser. When a page has JavaScript in it, the browser reads the code and does what it says โ€” right there on the page.

The code goes at the bottom

In the program below, the JavaScript sits near the bottom of the page, just before the end. That is on purpose. The browser reads a page from the top down, in order. The code must come after the heading and the button, so they already exist when the code goes looking for them.

What your program will do

Your page starts with a big heading that says "Click the button!" and one button. Click the button, and the heading's words change to "Hello world!" You made a page do something. That is programming.

Your First JavaScript Program

Do it with a grown-up:

1. Open a plain text editor (a grown-up can help you find one).

2. Tap Copy the code below and paste the whole thing into the editor. You can also select the code by hand and copy it that way.

3. Save the file with the name my-page.html

4. Open the file in a web browser. Your page appears!

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first JavaScript page</title>
</head>
<body>
<h1>Click the button!</h1>
<button>Change the words</button>
<script>
const myHeading = document.querySelector('h1');
let myButton = document.querySelector('button');
myButton.onclick = function() {
  myHeading.textContent = 'Hello world!';
};
</script>
</body>
</html>

What each part means

The top part (head): The page's setup. The title is the name shown on the browser tab.

<h1>Click the button!</h1>: The big heading, with its starting words.

<button>Change the words</button>: The button, with the words written on it.

The script part: The JavaScript. It finds the heading and stores it in a box named myHeading. It finds the button and stores it in a box named myButton. Then it tells the button: when you are clicked, change the heading's words to "Hello world!"

What You Should See

When the page opens, you see a big heading โ€” Click the button! โ€” and a button that says Change the words.

Click the button. The heading's words change to Hello world!

If nothing changes, check that you saved the file with .html at the end of its name, and that the script part is still at the bottom of the file, after the heading and the button.

Try Changing This

1. Change the words inside the quotes โ€” 'Hello world!' โ€” to your own words, like 'I did it!'. Save, reload the page, and click again.

2. Swap the heading-change line for a pop-up. Replace the line myHeading.textContent = 'Hello world!'; with alert('Hello!'); Now clicking the button pops up a little message box instead, just like MDN's lesson shows.

3. Change the heading's starting words โ€” the words between <h1> and </h1> โ€” to anything you like.

Words to Know

JavaScript: The programming language that makes web pages interactive โ€” able to answer clicks and change.

Browser: The program you use to look at web pages. It reads the page and runs its JavaScript.

Script: A piece of JavaScript code inside a page. In HTML it sits between <script> and </script>.

Variable: A named box that holds something โ€” words, a number, or a part of the page โ€” so your code can use it again.

textContent: The words inside a part of a page. Setting it changes the words.

Click: Pressing a button or link. Code can wait for a click and then run โ€” that waiting is called handling an event.

Keep Exploring

This set of guides also has an HTML & CSS First Steps page โ€” how the page itself is built and painted โ€” and a cheat sheet of the top 10 programming languages for kids. Grown-ups who want every detail can read MDN's own JavaScript lessons, listed below.

Sources

MDN Web Docs, developer.mozilla.org โ€” "JavaScript basics" (JavaScript "adds interactivity to your website... responses when buttons are pressed"; the hello-world example const myHeading = document.querySelector('h1'); and myHeading.textContent = 'Hello world!'; scripts placed just before the closing body tag because the browser reads code in file order; alert('hello!') makes a pop-up box; variables with let; buttons wired with myButton.onclick). "HTML basics" (the page skeleton used in the starter: doctype, html, head, meta charset, title, body). Every line of the starter program is one of these MDN patterns, assembled into one small page.

Checked against MDN's lessons on November 7, 2026.

Related guides: Top 10 Programming Languages, Learning HTML & CSS, Learning Lua, Learning Scratch and Long Division Steps.