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