What is JavaScript?
HTML structures, CSS styles — JavaScript makes pages think and react. It is the third and most powerful web language.
What you will learn
- Explain what JavaScript does
- See JavaScript change a page live
- Understand why it powers the whole MERN stack
The language of behaviour
If HTML is the structure and CSS is the style, JavaScript is the behaviour — it makes pages respond to clicks, validate forms, fetch data, animate, and update without reloading.
It is a real programming language: it has variables, decisions, loops and functions. And it runs everywhere — in every browser, and (via Node.js — a way to run JavaScript on a server, outside the browser) on servers too. That is why one language, JavaScript, can power an entire stack (all the layers of an app, from the page you see down to the database).
The most popular all-JavaScript stack is called MERN. It is just four tools whose names start M, E, R, N: MongoDB (a database that stores your data), Express (a helper for building the server), React (a library for building the page you see), and Node.js (the engine that runs the JavaScript on the server). You do not need any of them yet — the point is simply that learning this one language, JavaScript, unlocks all four.
See it react
Here is the smallest taste of JavaScript. The <button> has an onclick — a little instruction that runs when the button is clicked. The <p> below starts with placeholder text and an id="msg" so JavaScript can find it.
<button onclick="document.getElementById('msg').textContent = 'You clicked me! 🎉'">
Click me
</button>
<p id="msg">Nothing has happened yet...</p>When you click, this part runs: document.getElementById('msg') finds the paragraph with id="msg", and .textContent = 'You clicked me! 🎉' replaces its words. So the text swaps from "Nothing has happened yet..." to "You clicked me!".
Note: Output: Before click: Nothing has happened yet... After click: You clicked me! 🎉 No page reload. JavaScript changed the text instantly. That live interactivity is impossible with HTML and CSS alone.
Tip: JavaScript is not Java — the names are similar but they are completely different languages. JavaScript is the web’s language.
Q. What does JavaScript add to a web page?
✍️ Practice
- Change the button example so the message says your own name.
- Add a second button that changes the text to something different.
🏠 Homework
- Write two sentences on what HTML, CSS and JavaScript each do, using your own words.