Welcome 🎉

logo

ReactLMS

Search
Light Mode
Contact Us

2 min to read

Contact us

No results for your search.
Sorry, an unexpected error occurred

Concept


Local storage is an HTML5 API that allows web applications to store data in the user's browser.

Data stored in local storage will not be deleted when the user closes the web browser. This makes storing local information simple and convenient.

Local storage has several important advantages when used in web applications:


How to use


To use local storage, we can use the setItem(), getItem(), and removeItem() methods.

Here is an example of how to use local storage to store a user's name in a web application:

// Lưu tên người dùng vào local storage
localStorage.setItem('username', 'John Doe');

// Lấy tên người dùng từ local storage
const username = localStorage.getItem('username');
console.log(username); // Output: John Doe

// Xóa tên người dùng khỏi local storage
localStorage.removeItem('username');






In the example above, we use the setItem() method to store the user's name in local storage with the key 'username' and the value 'John Doe'. Then, we use the getItem() method to retrieve the user's name from local storage and assign it to the variable username. Finally, we use the removeItem() method to delete the user's name from local storage.



Read more
On This Page