Sikau

JavaScript · Day 56 · about 25 min

Saving in the browser

localStorage remembers.

Pages that remember

Refresh a normal page and everything you typed is gone. But your Sikau progress survives — because it's saved. The simplest way for a page to remember things is localStorage.

setItem and getItem

localStorage.setItem("theme", "dark");
console.log(localStorage.getItem("theme"));
console.log(localStorage.getItem("missing"));

localStorage.removeItem("theme");
console.log(localStorage.getItem("theme"));

In a real browser, localStorage survives refreshes and restarts. In Sikau's practice space it's a stand-in that resets after each run, so your examples always start fresh.

The rest of this lesson

  • Saving objects with JSONexplain
  • Saving app state properlyexplain
  • Predict the outputpredict
  • Numbers come back as textpredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript