HTML5 HTML5 Web Storage and APIs 2 — Questions and Answers
Question 1: Which HTML5 API allows web pages to run scripts in background threads?
- Web Workers API (Correct answer)
- Service Workers API
- Background Tasks API
- Thread API
Correct answer: Web Workers API
The Web Workers API lets you run JavaScript in a separate background thread, preventing heavy computations from blocking the main UI thread.
Question 2: What is the main use case of the Service Worker API?
- Enabling offline functionality and caching via a proxy between browser and network (Correct answer)
- Running background data processing tasks
- Controlling web worker threads
- Managing browser notifications only
Correct answer: Enabling offline functionality and caching via a proxy between browser and network
Service Workers act as a network proxy, enabling offline support, background sync, and push notifications by intercepting fetch requests.
Question 3: Which method removes a specific item from localStorage?
- localStorage.removeItem(key) (Correct answer)
- localStorage.delete(key)
- localStorage.clear(key)
- localStorage.remove(key)
Correct answer: localStorage.removeItem(key)
The removeItem(key) method removes the key-value pair with the specified key from localStorage.
Question 4: What does the HTML5 Drag and Drop API's 'dataTransfer' object do?
- Holds the data being dragged during a drag-and-drop operation (Correct answer)
- Transfers data between web workers
- Streams data to the server
- Manages clipboard data
Correct answer: Holds the data being dragged during a drag-and-drop operation
The dataTransfer object holds the data and state of a drag-and-drop operation, allowing you to set and retrieve data being dragged.
Question 5: Which HTML5 API allows a web page to request full-screen mode for an element?
- Fullscreen API (Correct answer)
- Presentation API
- Screen API
- Display API
Correct answer: Fullscreen API
The Fullscreen API provides methods like requestFullscreen() to display a specific element in full-screen mode.
Question 6: What does the HTML5 Notification API enable?
- Displaying native OS-level notifications from a web page (Correct answer)
- Sending push messages to a server
- Showing in-page alert dialogs
- Broadcasting messages to other tabs
Correct answer: Displaying native OS-level notifications from a web page
The Notification API lets web pages request permission to display system-level notifications outside the browser window.
Which HTML5 API allows web pages to run scripts in background threads?