What is JavaScript?
JavaScript is the programming language that gives web pages behaviour, alongside HTML for structure and CSS for looks, and it also runs outside browsers.
A button can be visible and nicely styled without knowing what to do when you click it. JavaScript can supply those instructions.
Your goal: Make a blog button respond to a click, then explain why changing its color cannot repair a missing click handler.
Structure, style and functionality
A website's visible interface has three parts working together: structure, style and functionality. We use HTML to create the structure, CSS to style it, and JavaScript to add instructions for functionality.
Start with the layered illustration below. Each layer shows a different responsibility for the same page. Select a part to highlight it, then choose Combine layers to see how they fit together.
Some interactions work through HTML alone, and CSS can also create animations. Here, JavaScript supplies the custom Save response.
Now try it on a blog
Choose a prediction, test it on the blog, then explain the result.
After testing: what changed, and what stayed the same? Use that observation to explain your prediction.
Changing stages or removing/restoring CSS restarts this example. Saved state is temporary and is not stored in your account. The illustration has its own colors even without the card's CSS.Make one change yourself
The example below isolates the save button so you can see every instruction. It changes a label only; it does not store an article.
Read it in this order:
<button id="save">creates the button and gives it a name we can find.document.querySelector("#save")finds that button.buttonis the name we use for it in the following lines.addEventListener("click", ...)registers instructions to run when a click happens. Registering them does not click the button.button.textContent = "Saved"replaces its displayed words when those instructions run.
You do not need to write the event-handler syntax from memory yet. First connect each instruction to an observable result.
Predict: If you change only "Saved" to "Added to my reading list", what will the button say before the first click? What will it say after?
Try it: Change the quoted message, update the preview, then click the button. Before the click, HTML still supplies Save article. After the click, the handler supplies your new message.
Break it deliberately: Remove just button.textContent = "...";, leaving the surrounding lines in place. Update the preview and click again. The button still exists; its click handler now has no instruction that changes the label. Put the line back and test your repair.
You changed the button's background color, but its missing save handler is still missing. What should you expect?
You removed the blog's CSS but kept its HTML and working click handler. What should still happen?
A changed label is not proof of storage
Our demo changes the visible words and keeps temporary state. It does not send anything to a server or restore a saved article after reloading. A real reading-list feature needs a place to store the saved item as well as this interface response.
JavaScript can also run outside web pages, for example in Node.js. This lesson uses a browser because you can directly observe what a click changes.
Output and page changes are different
console.log sends a message to the console or output panel. It does not find a button or change its label.
Change the message inside the quotes and run it again. Notice where the new text appears. The quotes mark a text value; they are not part of the printed message.
You run console.log("Article saved"). What has that instruction demonstrated?
In the small HTML preview, when does the instruction inside the click handler change the button text?
Check your understanding
Use the explanation exercise below to diagnose a blog button that looks correct but does not respond. Give a reason and a way to check your repair, rather than just naming a language.
Then write your own console message in the coding exercise. Keep the distinction clear: printed output, a changed interface, and stored data are three different results.

