How to set localstorage item back to null.

David picture David · Mar 4, 2013 · Viewed 19k times · Source

I'm using a system to alert users when a major update has happened to a site, and I do it with LocalStorage, when I made the system, I made the system check if tip was "null", then set "tip" to true when they got the alert. Now, I would like to set the 'tip' localstorage back to null, and use "tip2" instead.

Would I do this? localStorage.setItem('tip', 'null');

Answer

Michael Theriot picture Michael Theriot · Mar 4, 2013

localStorage.removeItem('tip') if you are aiming to remove the key

localStorage.setItem('tip', 'null') if you just want to set it to the string "null"