Skip to content
Kuza Ndoto Academy

JavaScript Introduction

Beginner → IntermediateChapter 1 · Page 1 of 324 min readUpdated 15 Nov 2026

JavaScript is the programming language of the web. HTML gives a page its structure and CSS gives it style, but JavaScript makes it do things: react to clicks, check a form before it is sent, load new data without refreshing, and much more. Every modern browser can run it, so it is one of the most useful languages you can learn.

What is JavaScript?

JavaScript was created by Brendan Eich at Netscape in 1995 to add simple interactivity to web pages. Despite the name, it has almost nothing to do with Java; the name was chosen for marketing reasons at a time when Java was fashionable. The language is standardised under the name ECMAScript. The 2015 edition (often called ES6) was a huge update that added let, const, arrow functions, classes and modules, and a new edition has been released every year since. This series teaches modern JavaScript (ES2023 and later), the version all current browsers support.

JavaScript is a high-level, dynamically typed language. You don't manage memory yourself, and a variable can hold any kind of value. If you have learned Python, much will feel familiar, although JavaScript uses curly braces { } for blocks instead of indentation.

The three languages of the front end

A useful way to remember who does what on a web page:

LanguageJobExample
HTMLContent and structureA heading, a paragraph, a button
CSSPresentationThe button is yellow with rounded corners
JavaScriptBehaviourClicking the button adds an item to your cart

With JavaScript you can show and hide menus, validate phone numbers on a sign-up form, build games, draw charts, play audio, fetch exchange rates from an API and save a user's settings in the browser. Apps you use daily, from online banking dashboards to chat apps, rely on it heavily.

Where JavaScript runs

Your JavaScript code is executed by a JavaScript engine. Every browser ships one: V8 in Chrome and Edge, SpiderMonkey in Firefox and JavaScriptCore in Safari. The engine understands the language itself (variables, loops, functions). The browser then adds extra tools called Web APIs, such as the DOM for changing the page, events for reacting to the user and fetch for talking to servers.

In 2009 Ryan Dahl released Node.js, which takes the V8 engine out of the browser so JavaScript can run on servers and laptops. Node.js has no web page and therefore no DOM, but it adds its own tools for reading files, handling network requests and installing packages with npm. That is why one language can power both the page you see and the server behind it.

In the browser Your JavaScript code JS engine V8 · SpiderMonkey · JavaScriptCore Browser APIs DOM, events, fetch, localStorage, alert On a server or laptop (Node.js) Your JavaScript code V8 engine the same engine as Chrome Node.js APIs files, network, processes, npm packages (no DOM)
Figure 1. The language is the same everywhere; what changes is the set of extra tools around the engine. Only the browser gives you a page to control.

A first taste

Here is a complete web page with a little JavaScript at the bottom. When you click the button, the script finds the heading and changes its text. Press Try it yourself, click the button, then change the words and run it again.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My first script</title>
</head>
<body>
  <h1 id="greeting">Habari!</h1>
  <button id="translate">Translate to English</button>

  <script>
    const heading = document.getElementById("greeting");
    const button = document.getElementById("translate");

    button.addEventListener("click", () => {
      heading.textContent = "Hello!";
    });
  </script>
</body>
</html>

Don't worry about every word yet. document.getElementById finds an element, addEventListener waits for a click, and textContent changes the text. You will learn each piece in the DOM chapter.

JavaScript can also simply calculate and print results. The console.log() function writes a message to the browser's console, a panel developers use to check what their code is doing:

const name = "Amina";
const year = 2026;

console.log("Hello, " + name + "!");
console.log("JavaScript turned", year - 1995, "this year.");
Hello, Amina! JavaScript turned 31 this year.

Notice that console.log puts a space between values separated by commas. Each statement ends with a semicolon. JavaScript can often insert missing semicolons for you, but writing them yourself avoids a few confusing bugs.

Common mistake

JavaScript is case-sensitive. console.log works, but Console.log or console.Log causes an error. The same goes for your own names: total and Total are two different variables.

How to learn JavaScript well

Type the examples yourself instead of only reading them, and change them to see what happens. Keep the browser console open (the next pages show you how), because it tells you exactly what went wrong when code fails. Work through the chapters in order: the basics (variables, types, conditions and loops) come first, then functions, objects and arrays, and then the exciting part, controlling real web pages.

Key points

  • JavaScript adds behaviour to web pages; HTML is structure and CSS is style.
  • It was created in 1995, is standardised as ECMAScript and gets a new edition every year.
  • Browsers run it with an engine (such as V8) plus Web APIs like the DOM; Node.js runs it outside the browser.
  • console.log() prints values to the console, your main tool for seeing what code does.
  • JavaScript is case-sensitive and uses curly braces for blocks.
Up next · Getting StartedAdding JavaScript to a PageScript tags, external files, defer and where to put them.
→

Tip: use the ← and → keys to move between pages.