DEV Community

Cover image for How to avoid reset Javascript variables when refeshing page?
Lalit Kumar
Lalit Kumar

Posted on

How to avoid reset Javascript variables when refeshing page?

Everytime we refresh the page, the variables go back to zero (null) instead of the value we provided or it is stored by calculating the equation we wrote in the program. But we want our code to store those values as long as we want to keep it.
This article will be discussing the method to avoid this problem. We’ll discuss the code and other things.

Cause

Everytime we refresh the page, the variables go back to zero because everytime we refresh our code reinitializes.

Solution

In order to avoid the reinitialization, we need to store the data somewhere else. We can store it either in a cookie or localstorage.

Read more

Top comments (0)