HTML APIs and Integration introduces essential web technologies like the Geolocation API, Drag-and-Drop API, and Web Storage (LocalStorage and SessionStorage). These APIs enhance user experience by enabling location tracking, file management, and persistent data storage across web sessions. Below are 30 multiple-choice questions (MCQs) on these topics.
MCQs on HTML APIs and Integration
Geolocation API
Which method is used to get the current position of the user using the Geolocation API? a) getPosition() b) getCurrentPosition() c) getUserPosition() d) getLocation()
Which parameter is passed to the success callback function of the Geolocation API? a) Position object b) Location object c) Geolocation object d) Coordinates object
What does the Geolocation API’s error callback function provide? a) Geolocation coordinates b) A status message c) A message describing the error d) User’s last known location
Which method allows you to watch the position of the user continuously? a) watchPosition() b) getPosition() c) trackPosition() d) monitorPosition()
Which of the following is an optional parameter for the getCurrentPosition() method in the Geolocation API? a) timeout b) accuracy c) speed d) none of the above
Drag-and-Drop API
Which event is fired when an element starts being dragged in the Drag-and-Drop API? a) dragstart b) dragenter c) dragover d) drop
What event occurs when a dragged element is moved over a valid drop target? a) dragenter b) dragleave c) dragstart d) dragover
Which event occurs when the dragged element is dropped onto a valid drop target? a) drop b) dragstart c) dragenter d) dragend
What is the purpose of the event.preventDefault() method in drag-and-drop operations? a) To cancel the drag operation b) To enable a valid drop target c) To disable all drag events d) To mark the element as draggable
Which of the following attributes is used to specify that an element is draggable in HTML? a) draggable=”true” b) draggable=”yes” c) draggable=”enabled” d) draggable=”on”
Web Storage: LocalStorage and SessionStorage
What is the primary difference between LocalStorage and SessionStorage? a) LocalStorage is session-based; SessionStorage is persistent b) LocalStorage is persistent; SessionStorage is session-based c) LocalStorage is faster than SessionStorage d) There is no difference
Which method is used to store data in LocalStorage? a) localStorage.store() b) localStorage.setItem() c) localStorage.addItem() d) localStorage.write()
How do you retrieve a value stored in LocalStorage? a) localStorage.retrieve() b) localStorage.get() c) localStorage.getItem() d) localStorage.read()
Which of the following is true about data stored in SessionStorage? a) It persists across multiple browser tabs b) It persists even after the browser is closed c) It is cleared when the browser tab is closed d) It can be shared across different browsers
Which method is used to remove a specific item from LocalStorage? a) localStorage.remove() b) localStorage.deleteItem() c) localStorage.removeItem() d) localStorage.clearItem()
General Web Storage and Integration
How do you remove all data from LocalStorage? a) localStorage.clear() b) localStorage.removeAll() c) localStorage.clearAll() d) localStorage.deleteAll()
Which of the following statements is correct about the data in LocalStorage? a) It is automatically cleared after 30 days b) It is cleared when the browser is closed c) It is persistent across page reloads and tabs d) It can only store string values
How can you check whether a particular key exists in LocalStorage? a) Using localStorage.hasItem() b) Using localStorage.exists() c) Using localStorage.getItem() and checking for null d) Using localStorage.keyExists()
Which of the following is a valid operation on SessionStorage? a) Storing data that lasts across browser sessions b) Storing data that persists even if the user navigates away c) Storing data that is cleared when the page is refreshed d) Storing data that persists after closing the tab
What is the maximum storage capacity of LocalStorage per domain? a) 2MB b) 5MB c) 10MB d) 20MB
Geolocation and Integration
How do you enable the Geolocation API in a web application? a) Use the <geolocation> tag b) Use JavaScript to access navigator.geolocation c) Enable the Geolocation feature in the browser settings d) Set a geolocation header in the request
Which of the following can you obtain using the Geolocation API? a) Latitude and longitude b) Speed and altitude c) Accuracy of the position d) All of the above
Which of the following describes the security requirement for accessing the Geolocation API? a) It requires a secure HTTPS connection b) It requires a password c) It requires user consent d) It does not require any special security
Which method in the Drag-and-Drop API is used to define what happens when a drag operation ends? a) dragstart() b) dragend() c) drop() d) dragleave()
What does the Drag-and-Drop API’s dragover event allow? a) Dragging the element b) Specifying the position of the drop c) Moving the target element d) None of the above
SessionStorage and Data Handling
Can data in SessionStorage be accessed from a different window or tab in the same browser? a) Yes, it is accessible across tabs b) No, it is only accessible from the same tab c) Yes, but only if the same domain is used d) No, it is not accessible at all
How do you set the expiration time for data stored in SessionStorage? a) SessionStorage does not support expiration times b) By using the setTimeout() function c) By using an expiration attribute d) By setting the time in the SessionStorage API
Which of the following is NOT a valid data type that can be stored in LocalStorage or SessionStorage? a) String b) Number c) Object (directly) d) Array
Which of the following is a correct way to store an object in LocalStorage? a) localStorage.setItem(“user”, {name: “John”, age: 30}) b) localStorage.setItem(“user”, JSON.stringify({name: “John”, age: 30})) c) localStorage.storeItem(“user”, {name: “John”, age: 30}) d) localStorage.addItem(“user”, {name: “John”, age: 30})
What is the maximum amount of data that can be stored in SessionStorage per domain? a) 5MB b) 10MB c) 2MB d) 50MB
Answer Key
Qno
Answer
1
b) getCurrentPosition()
2
a) Position object
3
c) A message describing the error
4
a) watchPosition()
5
a) timeout
6
a) dragstart
7
d) dragover
8
a) drop
9
b) To enable a valid drop target
10
a) draggable=”true”
11
b) LocalStorage is persistent; SessionStorage is session-based
12
b) localStorage.setItem()
13
c) localStorage.getItem()
14
c) It is cleared when the browser tab is closed
15
c) localStorage.removeItem()
16
a) localStorage.clear()
17
c) It is persistent across page reloads and tabs
18
c) Using localStorage.getItem() and checking for null
19
c) Storing data that is cleared when the page is refreshed
20
b) 5MB
21
b) Use JavaScript to access navigator.geolocation
22
d) All of the above
23
a) It requires a secure HTTPS connection
24
b) dragend()
25
b) Specifying the position of the drop
26
b) No, it is only accessible from the same tab
27
a) SessionStorage does not support expiration times
28
c) Object (directly)
29
b) localStorage.setItem(“user”, JSON.stringify({name: “John”, age: 30}))