JavaScript Web APIs Explained

🚀 Web APIs in JavaScript If JavaScript is single-threaded… 👉 How does it handle setTimeout, fetch, or click events without freezing? The answer is Web APIs. What are Web APIs? 👉They are built-in features provided by the browser that allow JavaScript to interact with the web page and the outside world. 1. DOM API (Document Object Model) This lets you interact with HTML elements. ✔️ Change content ✔️ Add/remove elements ✔️ Handle user actions Example: document.getElementById("title").innerText = "Hello World!"; 2. Fetch API Used to get data from servers (APIs). ✔️ Fetch data from backend ✔️ Work with JSON ✔️ Build dynamic apps Example: fetch("https://lnkd.in/dQeGAVaB") .then(res => res.json()) .then(data => console.log(data)); 3. Timer APIs Helps you control time-based execution. ✔️ setTimeout → run once after delay ✔️ setInterval → run repeatedly Example: setTimeout(() => console.log("Hello after 2 sec"), 2000); 4. Geolocation API Access user's location (with permission). ✔️ Latitude & Longitude ✔️ Location-based apps 5. Web Storage API Store data in the browser. ✔️ localStorage (permanent) ✔️ sessionStorage (temporary) Example: localStorage.setItem("user", "Kavi"); 6. Event Handling API Respond to user actions like clicks, typing, etc. Example: button.addEventListener("click", () => { console.log("Button clicked!"); }); >>JavaScript is single-threaded, but Browser APIs + Event Loop make it feel asynchronous! #JavaScript #WebDevelopment #Frontend #Programming #BrowserAPIs #100DaysOfCode

To view or add a comment, sign in

Explore content categories