JavaScript Window sessionStorage property

The JavaScript Window sessionStorage property is an object that provides access to the session storage of the current browser window. It allows you to store and retrieve data using key-value pairs, and the data is automatically deleted when the user closes the window or navigates to a different website.

Here are some examples of how the sessionStorage property can be used in JavaScript code:

  1. To store a value in the session storage, you can use the following code:
// store the value in the session storage
sessionStorage.setItem('key', 'value');
  1. To retrieve a value from the session storage, you can use the following code:
// retrieve the value from the session storage
var value = sessionStorage.getItem('key');
  1. To remove a value from the session storage, you can use the following code:
// remove the value from the session storage
sessionStorage.removeItem('key');

Overall, the sessionStorage property provides a convenient way to store and retrieve data in the session storage of the current browser window. It allows you to store data that is automatically deleted when the user closes the window or navigates to a different website, and it is a useful tool for tasks such as saving user preferences or other temporary data.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: