MCQs on HTML APIs and Integration | HTML

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

  1. Which method is used to get the current position of the user using the Geolocation API?
    a) getPosition()
    b) getCurrentPosition()
    c) getUserPosition()
    d) getLocation()
  2. 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
  3. 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
  4. Which method allows you to watch the position of the user continuously?
    a) watchPosition()
    b) getPosition()
    c) trackPosition()
    d) monitorPosition()
  5. 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

  1. Which event is fired when an element starts being dragged in the Drag-and-Drop API?
    a) dragstart
    b) dragenter
    c) dragover
    d) drop
  2. What event occurs when a dragged element is moved over a valid drop target?
    a) dragenter
    b) dragleave
    c) dragstart
    d) dragover
  3. Which event occurs when the dragged element is dropped onto a valid drop target?
    a) drop
    b) dragstart
    c) dragenter
    d) dragend
  4. 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
  5. 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

  1. 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
  2. Which method is used to store data in LocalStorage?
    a) localStorage.store()
    b) localStorage.setItem()
    c) localStorage.addItem()
    d) localStorage.write()
  3. How do you retrieve a value stored in LocalStorage?
    a) localStorage.retrieve()
    b) localStorage.get()
    c) localStorage.getItem()
    d) localStorage.read()
  4. 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
  5. 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

  1. How do you remove all data from LocalStorage?
    a) localStorage.clear()
    b) localStorage.removeAll()
    c) localStorage.clearAll()
    d) localStorage.deleteAll()
  2. 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
  3. 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()
  4. 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
  5. What is the maximum storage capacity of LocalStorage per domain?
    a) 2MB
    b) 5MB
    c) 10MB
    d) 20MB

Geolocation and Integration

  1. 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
  2. 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
  3. 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
  4. 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()
  5. 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

  1. 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
  2. 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
  3. 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
  4. 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})
  5. 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

QnoAnswer
1b) getCurrentPosition()
2a) Position object
3c) A message describing the error
4a) watchPosition()
5a) timeout
6a) dragstart
7d) dragover
8a) drop
9b) To enable a valid drop target
10a) draggable=”true”
11b) LocalStorage is persistent; SessionStorage is session-based
12b) localStorage.setItem()
13c) localStorage.getItem()
14c) It is cleared when the browser tab is closed
15c) localStorage.removeItem()
16a) localStorage.clear()
17c) It is persistent across page reloads and tabs
18c) Using localStorage.getItem() and checking for null
19c) Storing data that is cleared when the page is refreshed
20b) 5MB
21b) Use JavaScript to access navigator.geolocation
22d) All of the above
23a) It requires a secure HTTPS connection
24b) dragend()
25b) Specifying the position of the drop
26b) No, it is only accessible from the same tab
27a) SessionStorage does not support expiration times
28c) Object (directly)
29b) localStorage.setItem(“user”, JSON.stringify({name: “John”, age: 30}))
30a) 5MB

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top