JavaScript

JavaScript is a programming language that runs in your browser and lets a web page react to what you do. It works alongside HTML, which holds the content, and CSS, which controls how it looks. Every major browser runs it, and it can run on servers too, through tools such as Node.js.

What JavaScript does on a web page

Picture a floor area calculator on a builder's website. You change the width from 4 to 5 metres, and the area changes from 12 to 15 square metres straight away. A few lines of JavaScript are listening for that change. They do the sum and write the new answer into the page, without loading another one.

The same idea is behind menus that open when you tap them, forms that check your details before sending, and maps you can drag around. Most of the interactive parts of a modern website run on it.

How Google reads JavaScript websites

Google crawls a page's HTML first. It then renders the page, running the scripts to see the finished result, and that second step can happen some time later. So anything that only appears once the scripts have run may take longer to be picked up.

Not every crawler renders pages at all. Some other search engines and many AI crawlers read the HTML and stop there. That's why it's safest to have your main copy, headings, and links in the HTML itself, and to use JavaScript to add to the page.

Keeping scripts light

Every script has to be downloaded, read, and run before it does anything. On an older phone, too many scripts can make a page slow to load and slow to respond when someone taps it. Scripts loaded from other companies, for things like live chat and advertising, are often the heaviest. Loading scripts only on the pages that need them, and holding back the ones that aren't urgent, helps keep a site quick.

Scripts in our free marketing tools

Our free tools run on small scripts like the calculator above, so each answer is worked out in your own browser.

  1. Our SERP preview tool
    if (kind === "serp-preview") { tool.querySelector("[data-preview-title]").textContent = fields.title; tool.querySelector("[data-preview-description]").textContent = fields.description;…form.addEventListener("input", update);
    The preview updates as you type

    Our SERP preview tool shows how a title and description might look in Google's results. Every time you type, the script reads the form, puts your words into the mock result, and counts the characters. It all happens on the page you're already on, with nothing reloading.

  2. Our ROAS and PPC budget calculators
    function update() { const result = calculator.dataset.calculator === "roas" ? roas(values.spend, values.revenue) : ppc(values.budget, values.cpc, values.rate);…inputs.forEach((input) => input.addEventListener("input", update));
    Every box recalculates the result

    The ROAS and PPC budget calculators work the same way. Each box listens for a change, and the update function runs the right sum for that calculator and writes the answer into the page straight away.

More web design glossary terms

These web design and development glossary terms cover how websites are built, hosted, secured and used on every screen. Each definition shows the idea in a diagram with a practical example, so briefs, quotes and conversations with your web team are easier to follow.