How to delete Web Storage?

Storing sensitive data on local machine could be dangerous and could leave a security hole. The Session Storage Data would be deleted by the browser immediately after the session gets terminated.

To clear a local storage setting you would need to call localStorage.remove('key'); where 'key' is the key to the value you want to remove. If you want to clear all settings, you need to call localStorage.clear() method.


         // Reset number of hits.
         if( localStorage.hits ){
            localStorage.hits = Number(localStorage.hits) +1;
         } else{
            localStorage.hits = 1;
         document.write("Total Hits :" + localStorage.hits );
      <p>Refreshing the page would not to increase hit counter.</p>
      <p>Close the window and open it again and check the result.</p>

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 28-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started