TalentJR

Lesson 13

Local Storage

Save data in the browser

1What is Local Storage?✨

Local Storage is a feature in web browsers that allows you to store data persistently on the user's computer. This means that the data will remain even after the browser is closed!

2Why Use Local Storage?🎯

  • ✓ Save user preferences
  • ✓ Keep track of game scores
  • ✓ Store data without needing a server
  • ✓ Improve user experience by remembering information

3Getting Started with Local Storage💡

You can easily store data using the `localStorage` object. Here’s how to save a simple value:

💻 code
localStorage.setItem("username", "Student123");

This command saves the username "Student123" under the key "username".

4Retrieving Data from Local Storage🚀

💻 code
To access the data you've stored, use `getItem()`. For example:
💻 code
let username = localStorage.getItem("username");
console.log(username); // Outputs: Student123

This will retrieve the username you saved earlier and display it in the console.

5Removing Data from Local Storage🔍

💻 code
If you want to delete an item, you can use `removeItem()`. Here's how:
💻 code
localStorage.removeItem("username");

This command removes the "username" entry from Local Storage, freeing up space!

6Using Local Storage with JSON⭐

You can store more complex data by using JSON. First, convert your object to a string:

💻 code
let user = { name: "Alice", age: 15 };
localStorage.setItem("userData", JSON.stringify(user));

7To retrieve it back and convert it into an object, use:🧩

💻 code
let storedUser = JSON.parse(localStorage.getItem("userData"));
console.log(storedUser.name); // Outputs: Alice

8What You'll Build This Grade🎈

  • ✓ A web app that remembers user settings
  • ✓ A simple game that saves high scores
  • ✓ A to-do list that retains tasks between sessions
  • ✓ A profile page that saves user information

🎯 Practice Challenges

Master Local Storage by completing all 3 difficulty levels

🟢 EASY

Local Storage - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Local Storage - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Local Storage - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Local Storage? 🚀

Complete the challenges, take the quiz and keep your learning streak going!