localStorage FTW!

Have you ever thought how to use LocalStorage for some purpose in your project?

This is a super old topic but anyways I want to give my input on it. Well is not complicated at all, there are some considerations to take but is not hard to use.

First of all, you need to know that there are sessionStorage and localStorage the differences between them are the following if you want the data to be maintained only until the browser window closes you use sessionStorage but if you want to keep your data and remove it when you want then you can use localStorage.

To create your first local storage use setItem()


If you read out the myColor key using getItem():

let color = localStorage.getItem('myColor');  
// -> "blue"

Then you can remove it whenever you want using removeItem():

const myColor = localStorage.getItem('myColor');  
// -> null

Well you are good to go,

Thanks for reading, see you in the next chapter!


Victor Velazquez

Coder, Musician, Startups, Passionate Dancer & Life Lover. Director of Engineering at MagmaLabs, Co-founder of Web Dev Talks, Co-founder of Voltaire, Co-founder of Paqkit, Ex-co-founder of Zaznova.

Subscribe to The zazvick's blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!