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
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
Which of the following is a method of the Geolocation API?
A) getPosition()
B) findCoordinates()
C) getCurrentPosition()
D) locateDevice()
The Geolocation API requires which type of user consent?
A) Implicit consent
B) Explicit consent
C) Automatic consent
D) No consent
What parameter is NOT part of the getCurrentPosition() method?
A) Success callback
B) Error callback
C) Options object
D) Response object
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)
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
What is the maximum storage capacity for Local Storage in most modern browsers?
A) 5MB
B) 50MB
C) 10MB
D) 500KB
Which method is used to store data in Local Storage?
A) saveItem()
B) setItem()
C) addItem()
D) putItem()
What will sessionStorage.getItem('name') return if the key 'name' doesn’t exist?
A) Undefined
B) Null
C) Error
D) Empty string
Can JavaScript objects be stored directly in Local Storage?
A) Yes
B) No
Canvas API for Graphics
What HTML element does the Canvas API rely on?
A) <svg>
B) <div>
C) <canvas>
D) <img>
Which method is used to draw a rectangle in the Canvas API?
A) drawRect()
B) createRectangle()
C) fillRect()
D) rectangle()
What is the default color for shapes in the Canvas API?
A) Transparent
B) Black
C) White
D) Gray
How do you clear the entire canvas?
A) clearCanvas()
B) clearRect(0, 0, width, height)
C) resetCanvas()
D) removeCanvas()
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
What permission is required to send notifications through the Notifications API?
A) Geolocation
B) Storage access
C) User consent
D) None
Which method requests user permission for notifications?
A) requestPermission()
B) askPermission()
C) grantNotification()
D) authorizeNotifications()
What is the default value of Notification.permission in browsers?
A) Allowed
B) Denied
C) Prompt
D) Granted
What is the primary method to display a notification using the Notifications API?
A) new Notification()
B) showNotification()
C) createNotification()
D) sendNotification()
Can you style the appearance of a browser notification using CSS?
A) Yes
B) No
Mixed Concepts
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
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
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
Which API is suitable for creating dynamic graphics and animations?
A) Notifications API
B) Canvas API
C) Storage API
D) Geolocation API
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
Which API does NOT involve persistent data storage?
A) Web Storage API
B) Notifications API
C) IndexedDB API
D) Local Storage API
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
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
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
Which API provides methods for two-way data binding?