Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Using localStorage and sessionStorage | Storage, File Handling, and Geolocation
Quizzes & Challenges
Quizzes
Challenges
/
JavaScript Web APIs Essentials

bookUsing localStorage and sessionStorage

When you want to store data on the user's browser, HTML provides two important storage APIs: localStorage and sessionStorage. Both allow you to save key-value pairs as strings, but they differ in how long the data persists and when it is available.

localStorage saves data with no expiration time. This means that if you store something in localStorage, it will still be there even after the user closes and reopens the browser, or restarts their computer. This is useful for things like saving user preferences, themes, or login states that you want to remember across sessions.

sessionStorage, on the other hand, only keeps data for the duration of the page session. As soon as the user closes the browser tab or window, the data is cleared. sessionStorage is best used for temporary data that is only relevant while the user is on a specific page or during a single visit, such as wizard progress or temporary form data.

Both storage types are easy to use. You set an item with setItem(key, value) and get it back with getItem(key). Remember, all data is stored as strings, so you may need to use JSON.stringify and JSON.parse for objects or arrays.

index.html

index.html

script.js

script.js

copy
question mark

Which statement about localStorage and sessionStorage is correct?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookUsing localStorage and sessionStorage

Свайпніть щоб показати меню

When you want to store data on the user's browser, HTML provides two important storage APIs: localStorage and sessionStorage. Both allow you to save key-value pairs as strings, but they differ in how long the data persists and when it is available.

localStorage saves data with no expiration time. This means that if you store something in localStorage, it will still be there even after the user closes and reopens the browser, or restarts their computer. This is useful for things like saving user preferences, themes, or login states that you want to remember across sessions.

sessionStorage, on the other hand, only keeps data for the duration of the page session. As soon as the user closes the browser tab or window, the data is cleared. sessionStorage is best used for temporary data that is only relevant while the user is on a specific page or during a single visit, such as wizard progress or temporary form data.

Both storage types are easy to use. You set an item with setItem(key, value) and get it back with getItem(key). Remember, all data is stored as strings, so you may need to use JSON.stringify and JSON.parse for objects or arrays.

index.html

index.html

script.js

script.js

copy
question mark

Which statement about localStorage and sessionStorage is correct?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1
some-alt