-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path79_session_storage.js
19 lines (12 loc) · 1.93 KB
/
79_session_storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Session storage is a web browser feature that allows web applications to store data temporarily on a user's device. The stored data is available only for the duration of the browser session and is cleared when the user closes the browser or tab.
// Here are the basic steps to use session storage in a web application:
// Set an item in session storage:
// To set an item in session storage, use the sessionStorage.setItem() method and pass in a key - value pair.For example, sessionStorage.setItem("username", "John");
// Get an item from session storage:
// To get an item from session storage, use the sessionStorage.getItem() method and pass in the key.For example, let username = sessionStorage.getItem("username");
// Update an item in session storage:
// To update an item in session storage, use the sessionStorage.setItem() method and pass in the same key with the updated value.For example, sessionStorage.setItem("username", "Jane");
// Remove an item from session storage:
// To remove an item from session storage, use the sessionStorage.removeItem() method and pass in the key.For example, sessionStorage.removeItem("username");
// Session storage works similarly to local storage, but it's more suitable for storing temporary data that is not needed after the browser session ends. Like local storage, session storage can store only string key-value pairs. To store other data types such as objects, arrays, or numbers, you need to convert them to strings using methods such as JSON.stringify() and JSON.parse().
// It's important to use session storage responsibly and securely, and to comply with privacy regulations such as the EU General Data Protection Regulation (GDPR) and the California Consumer Privacy Act (CCPA). Users should be informed about the use of session storage and given the option to opt-out or manage their preferences. Additionally, sensitive data such as passwords or credit card numbers should not be stored in session storage.