Favorites

DOM Storage.getItem() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Storage.getItem()
DOM Storage MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The getItem() method reads the value stored under a key in localStorage or sessionStorage, returning null if there is none.

Description

The getItem() method returns the string stored under a key, or null if there's nothing there. Use JSON.parse() for values that were stored as JSON, and ?? to provide a default.

Because missing keys return null rather than throwing, passing the result straight to JSON.parse() gives null for missing data, which is often what you want. Wrap the parse in try...catch in case the stored text has been corrupted or edited by hand.

Storage access can throw, for example in some private browsing modes or in sandboxed iframes, so wrap calls in try...catch where it matters. Both localStorage and sessionStorage support the method, and changes made in one tab fire a storage event in other tabs on the same origin.

Syntax

storage.getItem(keyName)

Parameters

  • keyNameThe key to read.

Return Value

The stored string, or null if the key doesn't exist.

Example

try {
  const theme = localStorage.getItem('theme') ?? 'light';
  console.log('theme:', theme);
  const saved = JSON.parse(localStorage.getItem('cart') ?? '[]');
  console.log('cart items:', saved.length);
} catch (e) {
  console.log('Storage unavailable:', e.name);
}

Browser Support

The following information will show you the current browser support for the Storage.getItem() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee