JavaScript
In short
JavaScript is the programming language that runs in web browsers to make pages interactive, and it also runs on servers through runtimes like Node.js.
What is JavaScript?
JavaScript is the programming language of the web. While HTML defines a page's structure and CSS defines its look, JavaScript makes the page interactive: it responds to clicks, validates forms, fetches new data, and updates content without reloading the page.
In the browser, JavaScript works with the DOM, the browser's object representation of the page. It is single-threaded, meaning it runs one piece of code at a time, but it handles slow tasks like network requests asynchronously with callbacks, promises, and async/await, so the page stays responsive while it waits.
JavaScript is no longer limited to browsers. Runtimes such as Node.js, Deno, and Bun run it on servers and developer machines, so one language can be used for the front end, the back end, and build tools. The language itself is standardized as ECMAScript, and a new edition is published every year.
Despite the similar name, JavaScript has nothing to do with Java; the name was a marketing decision in the 1990s. TypeScript is a separate language built on top of JavaScript that adds static types and compiles back to plain JavaScript.
Key takeaways
- JavaScript adds interactivity and logic to web pages.
- Every major browser runs it without plugins.
- It handles slow operations asynchronously with promises and
async/await. - Node.js, Deno, and Bun run JavaScript outside the browser.
- The official language specification is called ECMAScript.
Example
// Find the button and the counter text in the page
const button = document.querySelector("#like");
const label = document.querySelector("#count");
let likes = 0;
// Run this function every time the button is clicked
button.addEventListener("click", () => {
likes += 1;
label.textContent = `${likes} likes`;
});Readers ask
Are Java and JavaScript the same?
No. They are different languages with different designs and uses. The similar name came from a 1990s marketing decision, not from a technical relationship.
What is the difference between JavaScript and ECMAScript?
ECMAScript is the official specification that defines the language, and JavaScript is the name of the language that implements it. Names like ES2015 or ES2025 refer to yearly editions of that specification.
Can JavaScript be used for back-end development?
Yes. Runtimes like Node.js, Deno, and Bun let JavaScript run on servers, where it is commonly used to build APIs and web applications.
Often compared
- JavaScript vs TypeScriptJavaScript is the dynamically typed language that browsers and Node.js run, while TypeScript is a superset that adds static types and compiles to JavaScript.
- Python vs JavaScriptPython is a general-purpose language known for readable code and its data and AI libraries, while JavaScript is the web's language, run by browsers and Node.js.
See also
- TypeScriptWeb Development, p. 50TypeScript is a programming language built on JavaScript that adds static types, catching many bugs before the code runs, and compiles to plain JavaScript.
- DOMWeb Development, p. 13The DOM is the browser's in-memory tree of objects representing a web page, which JavaScript can read and change to update what the user sees.
- HTMLWeb Development, p. 18HTML is the markup language that defines the structure and content of web pages, such as headings, paragraphs, links, images, and forms.
- PromiseProgramming Fundamentals, p. 46A promise is an object that represents the eventual result of an asynchronous operation, letting code react to success or failure once the work completes.
- Async/AwaitProgramming Fundamentals, p. 4Async/await is a syntax for writing asynchronous code that reads like ordinary step-by-step code, pausing at each await until a promise or task finishes.
- CallbackProgramming Fundamentals, p. 7A callback is a function passed as an argument to another function, which then calls it later, for example when a task finishes or an event happens.
- ES ModulesWeb Development, p. 15ES modules are JavaScript's built-in module system: each file keeps its own scope and shares code with other files through import and export.
Sources
Spotted a mistake or something missing on this page?Suggest an edit