Frontend Development › JavaScript & TypeScript
JavaScript
The programming language of the web.
Also known as: JS, JavaScript, ECMAScript language
JavaScript is the programming language of the web. It runs in every browser, where it makes pages interactive, and with Node.js (and similar runtimes) it also runs on servers and in command-line tools.
const prices = [10, 25, 8];
const total = prices.reduce((sum, p) => sum + p, 0);
document.querySelector("#total").textContent = `$${total}`;
document.querySelector("button").addEventListener("click", () => {
alert("Clicked");
});
What it does in the browser
- Reads and changes the page (DOM).
- Reacts to events: clicks, typing, scrolling (event handling).
- Talks to servers without reloading (fetch).
- Stores data in the browser (browser storage).
Outside the browser: web servers and APIs, build tools, scripts, desktop and mobile apps.
Key features
- Dynamically typed: variables hold any type, and types are checked at runtime. TypeScript adds static types.
- First-class functions: functions are values you can pass around.
- Prototype-based objects, with
classsyntax on top. - Single-threaded with an event loop: asynchronous work uses callbacks, promises and
async/await(event loop, promises). - Standardized as ECMAScript, with new features every year.
Quirks you’ll meet
==converts types, so use===.0.1 + 0.2isn’t exactly0.3(floating point).thisdepends on how a function is called.nullandundefinedare both “nothing” in different ways.typeof nullis"object".
None of these are reasons to avoid it, but they explain why linters and TypeScript are popular.
Not the same as Java
The name was marketing. They are unrelated languages.
It’s a good first language for the web: you can run it in the browser console right now.