Data MasteryFriday, January 23, 2026

JSON & Storage

Saving data and talking to APIs.

Advertisement

Support JS Mastery Path by checking out our sponsors.

The web is stateless. LocalStorage allows us to persist user preferences (like Dark Mode) between visits.

JSON: The Universal Language

const data = { id: 1, title: "Learn JS" };

// Object -> String (Packing)
const packed = JSON.stringify(data);
console.log(packed); // '{"id":1,"title":"Learn JS"}'

// String -> Object (Unpacking)
const unpacked = JSON.parse(packed);
console.log(unpacked.title);

Security Warning

NEVER store sensitive data

LocalStorage is accessible by any JavaScript running on your page (including analytics scripts or browser extensions).
NEVER store passwords, credit card info, or sensitive API tokens in LocalStorage. Use HttpOnly Cookies for that.

Using LocalStorage

// It only stores Strings!
localStorage.setItem("score", "100");

// Convert back to number when reading
const score = parseInt(localStorage.getItem("score"));
console.log(score + 50); // 150
Advertisement

Support JS Mastery Path by checking out our sponsors.