The difference between cookie, sessionstorage, localstorage

The difference between cookie, sessionstorage, localstorage

1. Size difference

cookie: The data is limited by different browsers, and the size generally cannot exceed 4k
sessionStorage - localStorage: Although there is also a storage size limit, it is much larger than cookies and can reach 5M or larger

2. Time limit

cookie: set a time limit, it will expire after a period of time, regardless of whether the browser is closed
sessionStorage: based on the window, as long as the window is not closed, it will always be there,

The sessionStorage property allows you to access a session Storage object corresponding to the current source. It is
similar to localStorage, except that the data stored in localStorage has no expiration time setting, while
the data stored in sessionStorage will be cleared when the page session ends.

localStorage: As long as it is not manually deleted, it will always exist

// Save data to sessionStorage sessionStorage.setItem('key', 'value');

// Get data from sessionStorage let data = sessionStorage.getItem('key');

// Delete saved data from sessionStorage sessionStorage.removeItem('key');

// Delete all saved data from sessionStorage sessionStorage.clear();

Not much text to say as shown in the figure

picture

Guess you like

Origin blog.csdn.net/weixin_53532986/article/details/120969268