How to count number of visitors for website in JavaScript?

To count number of visitors for website in JavaScript, increment the count in localStorage, the render it to an HTML element.

Insert this counter element and the script somewhere on a web page, then open the page to run it:

<div id="counter"></div>

<script>
  let count = parseInt(localStorage.getItem('visitorCounter') || '0');

  count++;

  localStorage.setItem('visitorCounter', count);

  document.getElementById('counter').innerHTML = count;
</script>