← JavaScript tutorial

JavaScript

Introduction to JavaScript

HTML structures a page and CSS styles it; JavaScript makes it interactive — responding to clicks, updating content without reloading, validating forms, fetching new data. It runs inside a <script> tag, either directly in the page or linked from a separate .js file.

Example: writing output onto the page

<p id="output">Loading...</p>

<script>
  document.getElementById("output").textContent = "Hello from JavaScript!";
</script>

Since there's no visible browser console in this preview, document.getElementById(...) finds an element already on the page by its id, and setting .textContent replaces whatever text is inside it. Every example in this tutorial follows this same pattern: find something on the page, change it — which is, at its core, most of what JavaScript is actually used for on a real site.

Try it yourself