MCSD MCSD Programming in HTML5 4 — Questions and Answers
Question 1: Which Web Storage API stores data with no expiration and persists across browser sessions?
- sessionStorage
- cookieStorage
- localStorage (Correct answer)
- cacheStorage
Correct answer: localStorage
`localStorage` stores key-value pairs persistently with no expiration until explicitly cleared, surviving browser restarts.
Question 2: What is the correct way to create a Promise that immediately resolves with the value 42?
- new Promise(resolve => resolve(42)) (Correct answer)
- Promise.reject(42)
- Promise.done(42)
- async Promise(42)
Correct answer: new Promise(resolve => resolve(42))
`new Promise(resolve => resolve(42))` creates a Promise and immediately calls `resolve`, settling it with the value 42.
Question 3: Which CSS property controls the stacking order of positioned elements?
- stack-order
- z-index (Correct answer)
- layer
- depth
Correct answer: z-index
`z-index` determines the stacking order of positioned elements; higher values appear in front of lower values.
Question 4: In HTML5, which element is used to group a set of `<option>` elements within a `<select>` dropdown?
- <group>
- <optgroup> (Correct answer)
- <fieldset>
- <datalist>
Correct answer: <optgroup>
`<optgroup>` groups related options inside a `<select>` element with an optional label, improving dropdown readability.
Question 5: What does the CSS `position: sticky` value do?
- Keeps the element fixed relative to the viewport at all times
- Positions the element relative to its nearest scrolling ancestor until a threshold is met (Correct answer)
- Removes the element from the normal document flow
- Makes the element overlap sibling elements
Correct answer: Positions the element relative to its nearest scrolling ancestor until a threshold is met
`position: sticky` behaves like `relative` until the element reaches a scroll threshold, then acts like `fixed` within its scroll container.
Question 6: Which JavaScript operator returns the data type of a variable as a string?
- instanceof
- typeof (Correct answer)
- typecheck
- datatype
Correct answer: typeof
The `typeof` operator returns a string indicating the type of the unevaluated operand, such as 'string', 'number', or 'object'.
Question 7: Which HTML5 element provides a container for fallback content when the browser does not support the `<canvas>` element?
- Content placed between the opening and closing <canvas> tags (Correct answer)
- <noscript>
- <object>
- <embed>
Correct answer: Content placed between the opening and closing <canvas> tags
Any HTML content placed between `<canvas>` and `</canvas>` is displayed as fallback in browsers that don't support the canvas element.
Which Web Storage API stores data with no expiration and persists across browser sessions?