Skip to content

JavaScript Tutorial Web APIs

Web APIs vs the JavaScript Language

Lesson 207 of 258 2 min read By Deepak Paswan Updated Oct 4, 2026

When you write document.querySelector() or fetch(), you are using JavaScript. But those two things are not part of the JavaScript language. They are Web APIs: features the browser provides, and that your JavaScript can call.

Two layers

The language (ECMAScript)Web APIs
Defined byECMA-262W3C, WHATWG and browser vendors
Exampleslet, function, Array, Promise, Map, Math, JSON, classdocument, fetch, setTimeout, localStorage, URL, console, Notification
Works inany JavaScript enginethe browser (some also in Node.js)
Needs a page?nomany do (the DOM), some do not (fetch)
script.js
JS
// Language: works anywhere JavaScript runs
const numbers = [3, 1, 2].sort();
console.log(numbers);            // → [1, 2, 3]

// Web API: provided by the browser
console.log(typeof document);    // → object
console.log(typeof fetch);       // → function
console.log(typeof localStorage);// → object

Why the difference matters

  • Environment: Node.js runs the language but has no document. So code that uses the DOM fails there with document is not defined.
  • Support: language features depend on the engine version; Web APIs depend on the browser and its permissions.
  • Where to look things up: MDN documents both, in sections called JavaScript and Web APIs.
  • Security: Web APIs are what let code touch the outside world, so browsers guard them with permissions, same-origin rules and user gestures.

Examples of Web APIs

AreaAPIs
The pageDOM, events, MutationObserver, IntersectionObserver, ResizeObserver
Networkfetch, WebSocket, EventSource
StoragelocalStorage, sessionStorage, IndexedDB, Cache API
Navigationlocation, History API, URL, URLSearchParams
DeviceClipboard, Notifications, Geolocation, Battery (limited)
MediaCanvas, Web Audio, MediaRecorder, Picture-in-Picture
Background workWeb Workers, Service Workers, timers

Many APIs are asynchronous

Most use events, callbacks or promises, because they involve waiting (a network reply, a user permission).

Permissions and user gestures

Sensitive APIs, such as clipboard reads, notifications and geolocation, need the user’s permission, and often a recent user action (a click). Browsers also require HTTPS (a “secure context”) for many of them.

Feature detection

Support varies, so check before you use something:

script.js
JS
if ("IntersectionObserver" in window) {
  console.log("IntersectionObserver is available");
}
if (typeof navigator.clipboard === "object") {
  console.log("Clipboard API object exists");
}

The rest of this chapter

You will meet the Web APIs that are useful on real websites: URL and URLSearchParams, the History API, the Clipboard API, the three observers, notifications and Web Workers. The DOM and fetch have chapters of their own.

info
No need to know them all
There are hundreds of Web APIs. Learn the ones you need as you build, and read the MDN page and its compatibility table each time.