Web APIs
Write a feature check for Worker.
Understand the topic
Browser APIs expose capabilities beyond HTML markup: DOM access, network requests, storage, media, and device-related features. JavaScript calls these interfaces, often asynchronously. Feature detection checks whether a capability exists; permission handling checks whether it may be used. A browser can support an API while the current context or user settings prevent its use.
Worked example
<button type="button" id="feature">Check browser support</button><p id="support" role="status"></p>
<script>document.querySelector("#feature").addEventListener("click", () => { document.querySelector("#support").textContent = "Geolocation API available: " + ("geolocation" in navigator); });</script>
This checks whether the interface is exposed without requesting location. It does not prove that the visitor will grant permission or that a position can be determined.
Practice
Write a feature check for Worker.
Show a suggested answer
if ("Worker" in window) {
// The worker interface is available; creation can still fail.
}Common mistake
Do not equate feature detection with permission or successful execution. Handle failures as part of the normal workflow.