What is JavaScript?

JavaScript lets websites do things when you interact with them, like clicking buttons or filling in forms.

Think of it like this

If HTML is a page's skeleton and CSS is its clothes, JavaScript is its brain and muscles. It notices when you poke the page - a click, a key press, a scroll - and decides what should happen next.

What's happening

Diagram showing JavaScript responding to a user click and updating the page content

Summary

JavaScript is the programming language that makes web pages interactive, reacting to what you do and updating the page without needing to reload it.

A Closer Look

JavaScript is a programming language that adds interactivity to web pages, and it's the main programming language built into every web browser. It lets a page respond to what you do: showing an error when you miss a field in a form, opening a menu when you tap an icon, or loading more posts as you scroll. Unlike HTML and CSS, it can make decisions, repeat steps, and do calculations - it's real code.

Much of JavaScript's work is listening for events - clicks, key presses, a page finishing loading - and changing the page in response. It can also fetch fresh data from an API in the background and update just one part of the page, which is how a web inbox shows new emails or a map loads new streets as you drag it, all without reloading. Because every browser can run it, JavaScript has become one of the most widely used languages in the world, and it now runs on servers and in desktop apps too.

JavaScript was created in 1995 by Brendan Eich at Netscape, the company behind one of the first popular web browsers, and the first version was famously written in around ten days. It was later handed to a standards body so every browser could follow the same official description of the language, known as ECMAScript. Because websites run JavaScript on your device automatically, browsers keep it inside a protective sandbox: a script on a web page can change that page, but it can't freely read the files on your computer or take control of other programs. That's a big part of why simply visiting an ordinary website is generally safe, even though it's running someone else's code.

Common Misconceptions

  • JavaScript and Java are completely different languages - they just share part of a name for historical marketing reasons.
  • JavaScript isn't only for websites - it also runs on servers (Node.js) and in apps.
  • You don't need to install anything to run JavaScript - every modern web browser has a JavaScript engine built in, and websites send their scripts along with the page.

Frequently asked questions

Is JavaScript hard to learn as a first language?

It's a popular first language because you can start straight away in any browser, with nothing to install, and see results immediately on a web page. The basics - storing values, making decisions, repeating steps - work much like any other language. It does have some quirky behaviour that can confuse beginners, but there are plenty of free tutorials and a huge community ready to help.

Can I turn JavaScript off, and should I?

Yes, every major browser has a setting to disable it, and some people do so for privacy or security. The catch is that much of the modern web depends on JavaScript, so many sites will break: menus won't open, forms won't submit, and some pages will appear completely blank. For most people, leaving it on and keeping the browser updated is the more practical choice.

What is TypeScript?

TypeScript is JavaScript with extra labels added that describe what kind of information each piece of code expects, such as text or a number. Those labels let tools spot many mistakes before the code ever runs. Browsers don't run TypeScript directly, so it's converted into ordinary JavaScript first. It's widely used on larger projects, and knowing plain JavaScript first makes it much easier to pick up.

How it connects

JavaScript works on top of HTML and CSS, and reaches out to other systems:

Try it yourself

Press F12 to open the browser console, type document.title and press Enter. JavaScript just read this page's title for you.