On page refresh, how to keep variable value?

Is there a way to keep a variable value on page refresh, if I have

var x=0;

but then a users does somethibng that makes that value become


and then the page is refreshed, is there a way to keep that value of 4 for the x variable or it will always reset to the original value?

You have these options (in order of preference):

  1. Sessions (server side)
  2. Cookies (client side)
  3. URL Query String

well, I been trying the url one but canĀ“t seem to get it right, I am trying it like this but oviously is not working, can you help me on it?

var enable_button=location.href+'?enable_button=enable_button' || 0;

I did the || 0 because I want it to assign the value 0 to it when the page is first loaded

You should really use Sessions because the others can be manipulated by the user.

Thank you for your help, I started rerading some posts about the sessions and found a recommendation to store the value in a hidden field, and that worked fine for what I am trying to do