Browser Runtime: DOM and Web APIs
You'll learn: How JavaScript in browsers gains superpowers through Web APIs that let it interact with web pages and the internet.
The Runtime is More Than Just the Engine
Remember that a JavaScript engine (like V8 or SpiderMonkey) executes your code, but it doesn't work alone in a browser. The browser runtime is the complete environment where your code runs, and it includes the engine plus a collection of powerful tools called Web APIs.
Think of it like this: the engine is the brain that understands JavaScript, but the Web APIs are the hands, eyes, and ears that let your code actually do things in the browser.
What Are Web APIs?
Web APIs are features provided by the browser itself—not part of core JavaScript—that allow you to:
- Manipulate the webpage using the DOM (Document Object Model), which represents the HTML structure
- Fetch data from servers across the internet
- Store information locally using localStorage or sessionStorage
- Handle timers with setTimeout and setInterval
- Access device features like geolocation or the camera
The JavaScript engine executes your code, but when you call these APIs, the browser handles the heavy lifting in the background.
Why This Matters
Without Web APIs, JavaScript would just be a language for doing calculations—it couldn't change what you see on screen, load new data, or remember user preferences. The browser runtime environment makes JavaScript useful for building interactive websites and web applications.
Key Takeaway: The browser runtime combines the JavaScript engine with Web APIs (like DOM, fetch, and localStorage) to give your code the ability to interact with web pages, servers, and local storage—turning JavaScript into a powerful tool for client-side applications.