localStorage
is enabled.try...catch
block to return true
if all operations complete successfully, false
otherwise.Storage.setItem()
and Storage.removeItem()
to test storing and deleting a value in window.localStorage
.const isLocalStorageEnabled = () => { try { const key = `__storage__test`; window.localStorage.setItem(key, null); window.localStorage.removeItem(key); return true; } catch (e) { return false; } };
isLocalStorageEnabled(); // true, if localStorage is accessible
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️