Web Development Web Development 3 — Questions and Answers
Question 1: What is the difference between localStorage and sessionStorage in browsers?
- localStorage is faster; sessionStorage is encrypted
- localStorage persists until cleared; sessionStorage clears when the tab closes (Correct answer)
- localStorage stores objects; sessionStorage stores only strings
- localStorage is shared across tabs; sessionStorage cannot be accessed by JavaScript
Correct answer: localStorage persists until cleared; sessionStorage clears when the tab closes
localStorage persists indefinitely across sessions, while sessionStorage is cleared when the browser tab or window is closed.
Question 2: In JavaScript, what does the 'Event Loop' primarily manage?
- DOM rendering and repaints
- Executing callback functions from the task queue when the call stack is empty (Correct answer)
- Memory allocation for variables
- Network request routing
Correct answer: Executing callback functions from the task queue when the call stack is empty
The event loop continuously checks if the call stack is empty, then pushes pending callbacks from the queue for execution.
Question 3: Which HTML element is semantically correct for the main navigation links of a website?
- <div id='nav'>
- <menu>
- <nav> (Correct answer)
- <header>
Correct answer: <nav>
The <nav> element is the semantic HTML5 landmark element specifically designed for major navigation link sections.
Question 4: What problem does CSS specificity solve?
- It determines the order in which CSS files are loaded
- It decides which CSS rule applies when multiple rules target the same element (Correct answer)
- It controls animation performance
- It sets the stacking order of elements
Correct answer: It decides which CSS rule applies when multiple rules target the same element
CSS specificity is a weight system that determines which conflicting rule takes precedence when multiple selectors target the same element.
Question 5: Which JavaScript Promise method runs all promises in parallel and rejects as soon as any one fails?
- Promise.all() (Correct answer)
- Promise.allSettled()
- Promise.race()
- Promise.any()
Correct answer: Promise.all()
Promise.all() executes all promises concurrently and short-circuits with a rejection if any single promise rejects.
Question 6: In a CSS Grid layout, what does 'fr' stand for and represent?
- Frame rate unit for animations
- Fractional unit — a share of the available free space (Correct answer)
- Frequency unit for responsive breakpoints
- Fixed ratio of the container's total width
Correct answer: Fractional unit — a share of the available free space
The fr unit represents a fraction of the leftover free space in the grid container after fixed-size tracks are accounted for.
Question 7: What is the purpose of the 'viewport' meta tag in HTML?
- Sets the page background color on mobile
- Controls how the browser scales and sizes the page on mobile devices (Correct answer)
- Enables GPU acceleration for animations
- Defines the default character encoding
Correct answer: Controls how the browser scales and sizes the page on mobile devices
The viewport meta tag instructs mobile browsers on how to scale the layout, commonly set to match the device's width.
What is the difference between localStorage and sessionStorage in browsers?