You have two options.
- Use
localStorage, as it persists on a device
- Use a backend server, that links to a database like MongoDB, SQL, etc. that is then able to store high scores based on user accounts/info.
For a game that is not highly complex, its better to use localStorage, since it stores data on a client's machine in the form of strings.
As a result, you don't NEED to let the user know about this, because all the data is hosted locally, and it is not sensitive info, like passwords, usernames, credit cards, names, etc. However, putting in a statement about how their data is used, and is stored locally, is never a bad thing, and its better to be safe than sorry.
2048 uses localstorage because their game doesn't compare your score to others or is an online multiplayer game.Therefore, you don't have to worry about hosting other servers, security, etc.
However, if you ever want to display a leaderboard or anything that requires a mix of various user scores, think like fortnite leaderboards, or any online multiplayer game, you will require a backend server linked to a database. This is highly complex though, and requires knowledge related to backend, database, and networking infrastructure and overall system design.