javascript close window remove localstorage code example
Example: How to clear localStorage when browser/tab is closing
window.addEventListener("beforeunload", () => localStorage.removeItem('storageVariable'));
window.addEventListener("beforeunload", () => localStorage.removeItem('storageVariable'));