I believe you need a backend language that runs on the server because using only Javascript on the client side every time a user send request to the page he will get the same exact Javascript code without a variable being modified.
Keep in mind that you don’t necessarily need a database, once you have a backend language you can keep track of the variable value in a text file on the server.
Possible solution
One possible solution you can make if you can't use PHP or any other backend language is to use a third-party service to keep track of that variable. In this case, every time the client Javascript will talk to the service (send a request to other server that can serve you as a database or file storage) and that server gives you the latest value.
You can use:
• Google Sheets API – store and retrieve data using JavaScript by treating a sheet like a database
• Firebase Realtime Database – a simple cloud database that works great with client-side JavaScript
• JSONBin or MockAPI – free online REST APIs to store and fetch JSON data
• GitHub Gist API – use gists to store data in a file-like way (not ideal for high traffic, but works for small-scale projects)
• Formspree or Getform – services that allow writing data via POST requests even without backend code