Difficulty: Easy
Correct Answer: Session storage is a per tab key value store that lasts for the duration of the page session; you create entries with code such as sessionStorage.setItem('key', 'value')
Explanation:
Introduction / Context:
HTML5 introduced Web Storage APIs to provide a simple key value storage mechanism in the browser, including localStorage and sessionStorage. These APIs allow JavaScript code to persist small amounts of data on the client side without using cookies. This question focuses on sessionStorage, asking what it is and how you typically create or store a value in it using JavaScript code.
Given Data / Assumptions:
Concept / Approach:
sessionStorage is part of the Web Storage API and provides a simple dictionary like object associated with a specific browsing context, usually a single tab or window. Data stored in sessionStorage is accessible only to pages from the same origin in that session and is cleared when the tab or window is closed. You can store values as strings using methods such as setItem and retrieve them with getItem. For example, sessionStorage.setItem("userName", "Ashwani") stores a key value pair under the key userName. This storage is entirely client side and does not involve Structured Query Language or Cascading Style Sheets rules.
Step-by-Step Solution:
Step 1: Recognise that sessionStorage is a browser side object exposed to JavaScript, separate from cookies and server databases.
Step 2: Understand that sessionStorage is scoped to the current tab or window and is cleared when that browsing session ends.
Step 3: Recall the basic usage pattern, where you call sessionStorage.setItem to save a key value pair and sessionStorage.getItem to retrieve it.
Step 4: Examine option a, which describes session storage as a per tab key value store lasting for the page session and shows a correct example of sessionStorage.setItem.
Step 5: Compare with options that incorrectly describe server side databases, cookies, or Cascading Style Sheets rules as session storage.
Verification / Alternative check:
According to web standards documentation, sessionStorage is defined as a Storage object with a lifetime equal to the page session, and data stored there is accessible within the same browsing context. Example code in tutorials often uses sessionStorage.setItem("key", "value") as the recommended way to store values. This documentation confirms that option a accurately describes both the behaviour and typical usage of session storage in HTML5.
Why Other Options Are Wrong:
Option b describes a server side database table, which is managed by database servers and accessed through Structured Query Language, not by using the sessionStorage API. Option c claims that session storage is a cookie shared across all tabs, which actually fits better with certain cookie behaviours; sessionStorage is not shared across tabs by default. Option d suggests that session storage is a Cascading Style Sheets rule type, which is unrelated to storage and persists styles, not key value data.
Common Pitfalls:
A common mistake is confusing sessionStorage with localStorage. localStorage persists even after the browser is closed and reopened, while sessionStorage is cleared when the tab or window closes. Another pitfall is trying to store complex objects without serialising them; sessionStorage stores strings, so objects should be JSON encoded and decoded. For exam purposes, remember that session storage is a per session, per tab key value store accessed through JavaScript with methods like sessionStorage.setItem.
Final Answer:
Session storage is a per tab key value store that lasts for the duration of the page session, and you typically create entries with code such as sessionStorage.setItem('key', 'value').
Discussion & Comments