Web Programming Web Programming 5 — Questions and Answers
Question 1: What is the purpose of the 'localStorage' API in web browsers?
- Stores data on the server for the current user
- Persists key-value data in the browser with no expiration (Correct answer)
- Temporarily stores session data cleared when the tab closes
- Caches images and CSS files locally
Correct answer: Persists key-value data in the browser with no expiration
localStorage stores string key-value pairs in the browser persistently, surviving page reloads and browser restarts until explicitly cleared.
Question 2: In CSS, which value of 'position' removes an element from the normal document flow and positions it relative to the viewport?
- relative
- absolute
- fixed (Correct answer)
- sticky
Correct answer: fixed
position: fixed removes the element from document flow and fixes its position relative to the browser viewport, so it stays visible when scrolling.
Question 3: What does the spread operator (...) do in JavaScript?
- Declares a rest parameter in a function
- Expands an iterable into individual elements (Correct answer)
- Creates a deep copy of nested objects
- Merges two class definitions
Correct answer: Expands an iterable into individual elements
The spread operator expands an iterable such as an array or object into its individual elements in contexts like function calls or array literals.
Question 4: Which of the following best describes a Single Page Application (SPA)?
- A website with only one HTML page and no links
- A web app that loads one HTML page and dynamically updates content without full page reloads (Correct answer)
- An app that only works on mobile devices
- A server-rendered site with one template
Correct answer: A web app that loads one HTML page and dynamically updates content without full page reloads
SPAs load a single HTML shell and update the DOM dynamically via JavaScript, avoiding full page reloads for faster navigation.
Question 5: What is the purpose of an API key in web development?
- Encrypts data sent between the client and server
- Authenticates and identifies the application making API requests (Correct answer)
- Stores the API's database credentials
- Compresses API responses for faster transfer
Correct answer: Authenticates and identifies the application making API requests
An API key is a unique identifier passed in requests to authenticate the calling application and control access to an API.
Question 6: In JavaScript, what does the 'Promise.all()' method do?
- Runs promises sequentially one after another
- Resolves when all passed promises resolve, or rejects if any reject (Correct answer)
- Retries failed promises automatically
- Returns the first promise to resolve
Correct answer: Resolves when all passed promises resolve, or rejects if any reject
Promise.all() takes an array of promises and resolves with an array of results when all resolve, or rejects immediately if any single promise rejects.
Question 7: Which CSS property controls the transparency of an HTML element?
- visibility
- display
- opacity (Correct answer)
- filter: blur()
Correct answer: opacity
The opacity property sets the transparency level of an element from 0 (fully transparent) to 1 (fully opaque).
What is the purpose of the 'localStorage' API in web browsers?