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:
localStorage.setItem("username", "Student123");This command saves the username "Student123" under the key "username".
4Retrieving Data from Local Storage🚀
To access the data you've stored, use `getItem()`. For example:let username = localStorage.getItem("username");
console.log(username); // Outputs: Student123This will retrieve the username you saved earlier and display it in the console.
5Removing Data from Local Storage🔍
If you want to delete an item, you can use `removeItem()`. Here's how: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:
let user = { name: "Alice", age: 15 };
localStorage.setItem("userData", JSON.stringify(user));7To retrieve it back and convert it into an object, use:🧩
let storedUser = JSON.parse(localStorage.getItem("userData"));
console.log(storedUser.name); // Outputs: Alice8What 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
Local Storage - Easy Challenge
Start with the basics. Perfect for beginners!
Local Storage - Medium Challenge
Get more challenging. Build your confidence!
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!
Keep learning
- ← Previous lessonLesson 12: Form HandlingCapture and validate user input
- Next lesson →Lesson 14: Timers & IntervalsSchedule and repeat actions
- Grade 9 courseJavaScript Advanced - Web MasteryJavaScript coding course for kids.
- Student ToolsFree calculators for studentsPercentage, fraction, ratio and marks calculators with steps.
- CBSEClass 8 CBSE & NCERT study materialMaths, Science and Computer chapters with solutions.
- Future SkillsExplore future skillsAI, robotics and new-age skills explained for students.