Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does javascript store variables and how long are they kept?

Tags:

javascript

This might be a bit general but, I'm wondering where are js variables stored? And are they kept when you click into new pages or every time the data is reset?

like image 679
OneZero Avatar asked Dec 07 '25 13:12

OneZero


1 Answers

They are reset every time you refresh.

There are multiple ways to persist them between reloads. e.g.

  • Webstorage http://en.wikipedia.org/wiki/Web_storage
  • cookies
  • You save them to the database and load them into a session. Then render server side.

For all of these methods you would need to persist these (generally due to some user interaction) and load these on page reload etc. It does not happen automatically, you have to explicitly do so.

like image 161
basarat Avatar answered Dec 09 '25 02:12

basarat