Overwriting data in a localStorage in JavaScript

You can overwrite data saved in storage under a specific key. Let's try and write some data:

localStorage.setItem('key', '1'); let value1 = localStorage.getItem('key'); console.log(value1); // shows '1'

Now let's ovewrite this data:

localStorage.setItem('key', '2'); let value2 = localStorage.getItem('key'); console.log(value2); // shows '2'

The user visits the site, then refreshes the page, then refreshes again, and so on. Make a page refresh counter. Display the counter value on the screen every time page is updated.