Session Storage is a web storage mechanism that allows web application to store key-value pairs in user’s browser session. It provides a way to store data temporarily while the user is browsing a particular website or until the browser session ends.
The data stored in Session Storage is scoped to a specific origin, which means it is accessible only within the same domain and protocol that created it. Other websites or tabs cannot access or modify this data.
Here’s an example to illustrate how Session Storage works:
// Storing data in Session Storage
sessionStorage.setItem('username', 'John');
sessionStorage.setItem('isLoggedIn', true);
// Retrieving data from Session Storage
const username = sessionStorage.getItem('username');
const isLoggedIn = sessionStorage.getItem('isLoggedIn');
console.log(username); // Output: John
console.log(isLoggedIn); // Output: true
// Updating data in Session Storage
sessionStorage.setItem('isLoggedIn', false);
// Removing data from Session Storage
sessionStorage.removeItem('username');
// Clearing all data from Session Storage
sessionStorage.clear();

Remember that the data stored in Session Storage will be available only within the same browser session and on the same domain that created it. If the user closes the browser or navigates away from the website, the data stored in Session Storage will be cleared.