Which browser APIs should a JavaScript developer know?
Most jobs only need a handful, and they fall into four groups.
Networking. The fetch function for HTTP requests, the WebSocket constructor for a persistent connection, and the EventSource constructor for server-sent events. In Node, the WebSocket and EventSource classes now exist as globals too, which is worth knowing if you write code that runs in both places.
Storage and state. Local storage and session storage for small pieces of text, the Cache API for storing responses, and the IndexedDB API for structured, sizeable data that survives a reload.
Timers and scheduling. The timer functions, the animation frame request for work tied to the display, and the idle callback for work that can wait.
Device and platform. The clipboard API, the geolocation API, the media devices API for cameras and microphones, the notifications API, and the share API for the system share sheet.
// Feature detection tells you what the runtime can do.
const features = {
fetch: typeof fetch !== "undefined",
localStorage: typeof localStorage !== "undefined",
clipboard: typeof navigator !== "undefined" && Boolean(navigator.clipboard),
notifications: typeof Notification !== "undefined",
webSocket: typeof WebSocket !== "undefined",
intersectionObserver: typeof IntersectionObserver !== "undefined",
};
for (const [name, supported] of Object.entries(features)) {
console.log(name, supported ? "available" : "not available");
}The pattern in the snippet is the one to remember. Feature detection with the typeof operator tells you what the current runtime supports, which is more reliable than sniffing the user agent string. A user agent check tells you what the browser claims to be, and it is wrong often enough that it causes real bugs.
Two categories are deliberately missing from that list. The first is anything that needs a secure context, such as the clipboard and the geolocation, which only work on a secure origin. The second is anything that is asynchronous about permission, such as the notifications and the media devices, where the API existing does not mean you have permission to use it. Both need their own handling at runtime.