Every time a menu opens, a form tells you a password is too short, or a map moves under your finger, JavaScript is doing it. If you have seen the word in an error message, a job advert or a browser setting and want to know what is JavaScript, here it is without the jargon.
JavaScript is a programming language, and it is the only one every web browser runs. A web page is built from three things working together, and each has its own job:
- HTML says what is on the page: headings, text, pictures, buttons
- CSS says how it looks: colours, fonts, spacing, layout
- JavaScript says what it does when you click, type or scroll
Think of it as a house. HTML is the walls and rooms, CSS is the paint and furniture, and JavaScript is the wiring that makes the lights come on when you press the switch.
In this article you will learn where JavaScript came from, what it actually does, how it is different from Java, where it runs besides the browser, and how to see it working on your own computer in about a minute.
So let’s get started.
Where it came from
JavaScript was written in 1995 by Brendan Eich at Netscape, the company behind the most popular browser of the time, famously in about ten days. It was meant to make pages a little livelier.
It is now looked after as a standard called ECMAScript, with a new version every year, and every browser follows it. That is why the same code runs in Chrome, Safari, Firefox and Edge.
What it actually does on a page
Reacting to you. Opening menus, showing a hidden answer, checking a form before it is sent.
Changing the page without reloading it. A new message appearing in your inbox, more posts loading as you scroll, a like counter going up.
Fetching data in the background. Search suggestions as you type, live prices, the weather, all asked for quietly while you stay on the same page.
Running whole apps. Gmail, Google Docs and online games are mostly JavaScript running in your browser.
JavaScript is not Java
The name was a piece of 1990s marketing, borrowed from Java, which was fashionable then. The two languages are unrelated apart from a few spellings, and a Java developer and a JavaScript developer do different jobs.
Where else it runs
With Node.js, JavaScript runs outside the browser too, on servers and in the tools developers use every day. Our page on what Node.js is explains how, and what npm is covers the package manager that comes with it.
See it working in a minute
Open any web page in Chrome or Edge and press F12, then click the Console tab. Type 2 + 2 and press Enter, and JavaScript answers 4. Type alert(‘Hello’) and press Enter, and a box pops up on the page.
That console is where developers test code and where JavaScript errors appear. Nothing you type there changes the website for anybody else, and it all disappears when you reload.
When JavaScript goes wrong
Because it runs in your browser, JavaScript errors show up on your screen. Script error is the message you see when the browser hides the details, and our page on what a syntax error is covers the mistakes that stop code before it runs.
Keep in mind that switching JavaScript off in your browser does not work as a fix for a broken site. Most modern sites stop working entirely without it, and some show only a blank page.
If you want to learn it
It is one of the easiest first languages, because all you need is a browser and a text editor. If you are a beginner, I recommend learning a little HTML and CSS first, since JavaScript mostly works on pages built with them, and our guide to what CSS is is a short start.
After that, timers are a good first real topic, and our guide to setTimeout in JavaScript walks through one of the most common.
FAQ(What Is JavaScript)
What is JavaScript used for?
Making web pages interactive, building web apps, and, with Node.js, running servers and developer tools.
Is JavaScript the same as Java?
No. The names are similar for marketing reasons, and the languages are unrelated.
Is JavaScript hard to learn?
It is one of the gentler first languages, because you can try it in any browser with nothing to install.
Should I turn JavaScript off?
For most people, no. It is needed by almost every site, and browsers already keep it from reaching your files.
Is JavaScript free?
Yes. It is built into every browser, and nobody has to pay to use or learn it.
If you have any issues, you can ask me via comment, and I will love to help you out.
Two words from your first lesson
Nearly every JavaScript tutorial uses these two terms early on, often without stopping to explain them.
- what a string is, how quotes mark text in code, and why “5” and 5 are not the same thing.
- what JSON is and why it won, the data format that grew out of JavaScript and is now used by almost every app.