3

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?

2 Answers 2

6

They are reset every time you refresh.

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

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.

Sign up to request clarification or add additional context in comments.

6 Comments

What if I want to keep some variables?
you'll need to roundtrip them to the server; consider using sessions or cookies for storing persistent state, e.g. the document.cookie api
@OneZero Web Storage, cookies, or your own DB.
It depends what server side technology you are using if it is ASP.Net you can also store it on the page viewstate as well
@Kiarash I'm assuming this isn't a simple postback scenario.
|
0

They stored in client memory and as Basarat mentioned they gone on each postbask or refresh

1 Comment

the whole description was not there when I commented at that time the sentence was just this "They are reset every time you refresh."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.