✨ First Steps in JavaScript
6th Grade 💻 Coding
HTML builds the page and CSS dresses it up, but what makes a button respond, a game move and a search box suggest words? JavaScript. It’s the programming language of the web browser, and it’s on almost every website in the world. In this lesson we write our first lines of JavaScript and see how it connects code to the page.
A language written in ten days
In 1995, a web browser company asked a programmer named Brendan Eich to create a small language that would run inside web pages. As the well-known story goes, he wrote the first version in about ten days. The name “JavaScript” was chosen mostly for marketing, because another language called Java was very famous at the time — but the two languages are completely different. Programmers like to joke that Java and JavaScript are related the way “car” and “carpet” are — only in name.
Since then it has grown a lot. Today every modern browser can run JavaScript, and it’s used not only on web pages but also on servers, in apps and in games. Together with HTML and CSS, it’s one of the three languages everyone who builds websites learns.
First lines
In JavaScript, the simplest way to show something is console.log("Hello"). The output appears in the console — a special window in the browser’s developer tools that programmers use for testing. console.log(2 + 3) shows 5. Just like in Python, numbers and text are different: "5" + 5 gives “55,” because JavaScript glues text and a number together when you add them.
You create a variable with the word let: let score = 0; and later score = score + 1;. Notice the semicolon at the end of the line — in JavaScript it’s common to end instructions with one. A condition is written with parentheses: if (score > 10) { console.log("You win!"); }. The condition goes in round parentheses, and the instructions that run go inside curly braces. That’s the biggest difference from Python, which uses a colon and indentation.
Connecting code to the page
JavaScript’s real power is that it can change the page while you’re looking at it. In an HTML page you can put a button and set it so that clicking it runs a function: <button onclick="sayHi()">Click me</button>. In the code you define the function: function sayHi() { alert("Hi there!"); }. Now every click pops up a little window that says “Hi there!” That’s an event — just like in Scratch.
Instead of a pop-up, you can change text on the page, switch a color, hide or show parts and add items to a list. That’s how the click counters, to-do lists and memory games you know from websites work. The browser keeps a “map” of every part of the page, and JavaScript can find any part by its name and change it.
How to practice safely
To practice, you can create an HTML file on your computer and add JavaScript code inside a <script> tag. Open the file in the browser, and you’ll see the output of console.log in the developer tools. There are also learning websites where you type code and see the result right away. As always, with a grown-up’s permission.
An important safety rule: never paste code that a stranger sent you into the developer tools or the console, even if they promise it will “give you a free gift” or “unlock something secret.” Code like that can steal accounts. Code you wrote yourself and understand — great. Code you don’t understand from a source you don’t know — don’t run it.
Key facts
- JavaScript was created in 1995 by Brendan Eich — according to the story, in about ten days.
- JavaScript and Java are two completely different languages.
- In JavaScript you show output for testing with console.log, and you create a variable with let.
- In JavaScript, blocks are marked with curly braces, and instructions usually end with a semicolon.
- Never run code that strangers send you in the console.
Quick quiz
What does JavaScript do on websites?
Who created JavaScript?
Is JavaScript a version of Java?
Which word creates a variable in JavaScript?
Where does the output of console.log appear?
What does "5" + 5 give in JavaScript?
How do you mark the block of a condition in JavaScript?
What should you do when a stranger sends code and asks you to paste it into the console?
💭 Think and talk about it
- On a website you know, find three things that respond to a click or to typing. How do you think they work?
- What’s the same and what’s different between a condition in Python and a condition in JavaScript?
- Why do you think it’s dangerous to run code you don’t understand?
Questions kids ask
Which should I learn first — Python or JavaScript?
Both are good choices. Python is easier to read and great for learning the ideas of programming. JavaScript is a good fit if you want to build websites and see the result in the browser. The ideas are the same, and once you learn one, you’ll pick up the other quickly.
How do you open the developer tools in a browser?
In most desktop browsers you press F12, or right-click on the page and choose “Inspect.” There you’ll find a Console tab. Use it only for code you wrote yourself.
Does JavaScript only work in the browser?
No. Today it also runs on servers, in phone and computer apps and in games. But the browser is where it was born, and where most people meet it.