MCQs on Working with Web APIs | JavaScript Advanced

Explore the practical power of Web APIs like Geolocation, Web Storage, Canvas Graphics, and Notifications. These tools enrich modern web applications, making them interactive, efficient, and user-friendly.


Geolocation API

  1. What does the Geolocation API primarily allow web applications to do?
    • A) Access device hardware
    • B) Determine a user’s location
    • C) Store data locally
    • D) Send notifications
  2. Which of the following is a method of the Geolocation API?
    • A) getPosition()
    • B) findCoordinates()
    • C) getCurrentPosition()
    • D) locateDevice()
  3. The Geolocation API requires which type of user consent?
    • A) Implicit consent
    • B) Explicit consent
    • C) Automatic consent
    • D) No consent
  4. What parameter is NOT part of the getCurrentPosition() method?
    • A) Success callback
    • B) Error callback
    • C) Options object
    • D) Response object
  5. The Geolocation API returns which object type containing the location data?
    • A) LocationData
    • B) Position
    • C) Coordinates
    • D) GPSData

Web Storage API (Local and Session Storage)

  1. What is the main difference between Local Storage and Session Storage?
    • A) Data encryption
    • B) Data persistence duration
    • C) Supported data types
    • D) Data size limit
  2. What is the maximum storage capacity for Local Storage in most modern browsers?
    • A) 5MB
    • B) 50MB
    • C) 10MB
    • D) 500KB
  3. Which method is used to store data in Local Storage?
    • A) saveItem()
    • B) setItem()
    • C) addItem()
    • D) putItem()
  4. What will sessionStorage.getItem('name') return if the key 'name' doesn’t exist?
    • A) Undefined
    • B) Null
    • C) Error
    • D) Empty string
  5. Can JavaScript objects be stored directly in Local Storage?
  • A) Yes
  • B) No

Canvas API for Graphics

  1. What HTML element does the Canvas API rely on?
  • A) <svg>
  • B) <div>
  • C) <canvas>
  • D) <img>
  1. Which method is used to draw a rectangle in the Canvas API?
  • A) drawRect()
  • B) createRectangle()
  • C) fillRect()
  • D) rectangle()
  1. What is the default color for shapes in the Canvas API?
  • A) Transparent
  • B) Black
  • C) White
  • D) Gray
  1. How do you clear the entire canvas?
  • A) clearCanvas()
  • B) clearRect(0, 0, width, height)
  • C) resetCanvas()
  • D) removeCanvas()
  1. Which property is used to set the color of the stroke in the Canvas API?
  • A) lineColor
  • B) strokeStyle
  • C) borderColor
  • D) outlineStyle

Notifications and Alerts API

  1. What permission is required to send notifications through the Notifications API?
  • A) Geolocation
  • B) Storage access
  • C) User consent
  • D) None
  1. Which method requests user permission for notifications?
  • A) requestPermission()
  • B) askPermission()
  • C) grantNotification()
  • D) authorizeNotifications()
  1. What is the default value of Notification.permission in browsers?
  • A) Allowed
  • B) Denied
  • C) Prompt
  • D) Granted
  1. What is the primary method to display a notification using the Notifications API?
  • A) new Notification()
  • B) showNotification()
  • C) createNotification()
  • D) sendNotification()
  1. Can you style the appearance of a browser notification using CSS?
  • A) Yes
  • B) No

Mixed Concepts

  1. Which API allows the browser to access and retrieve the user’s physical location?
  • A) Canvas API
  • B) Geolocation API
  • C) Storage API
  • D) Notifications API
  1. Which API would you use to store temporary data for a single tab session?
  • A) Local Storage API
  • B) Session Storage API
  • C) IndexedDB API
  • D) Geolocation API
  1. What does clearRect() in the Canvas API do?
  • A) Fills the canvas with a color
  • B) Clears a rectangular area
  • C) Removes the canvas from the DOM
  • D) Saves the canvas state
  1. Which API is suitable for creating dynamic graphics and animations?
  • A) Notifications API
  • B) Canvas API
  • C) Storage API
  • D) Geolocation API
  1. How can you ensure the user explicitly agrees to share their location?
  • A) Use a consent management API
  • B) Display a prompt via Geolocation API
  • C) Automatically detect location
  • D) It’s not required
  1. Which API does NOT involve persistent data storage?
  • A) Web Storage API
  • B) Notifications API
  • C) IndexedDB API
  • D) Local Storage API
  1. What is the key characteristic of session storage?
  • A) Data expires when the browser closes
  • B) Data persists indefinitely
  • C) Data encrypts automatically
  • D) Only text data can be stored
  1. The fillStyle property is used in the Canvas API to:
  • A) Define the stroke color
  • B) Define the fill color
  • C) Set the canvas background
  • D) Set the line width
  1. What happens if the browser denies notification permissions?
  • A) Notifications will still display
  • B) An error is thrown
  • C) Notifications won’t display
  • D) The app will prompt again
  1. Which API provides methods for two-way data binding?
  • A) Canvas API
  • B) Notifications API
  • C) Geolocation API
  • D) None of the above

Answer Key

QnoAnswer
1B) Determine a user’s location
2C) getCurrentPosition()
3B) Explicit consent
4D) Response object
5B) Position
6B) Data persistence duration
7A) 5MB
8B) setItem()
9B) Null
10B) No
11C) <canvas>
12C) fillRect()
13B) Black
14B) clearRect(0, 0, width, height)
15B) strokeStyle
16C) User consent
17A) requestPermission()
18C) Prompt
19A) new Notification()
20B) No
21B) Geolocation API
22B) Session Storage API
23B) Clears a rectangular area
24B) Canvas API
25B) Display a prompt via Geolocation API
26B) Notifications API
27A) Data expires when the browser closes
28B) Define the fill color
29C) Notifications won’t display
30D) None of the above

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