 <p>I'd check that <code>localStorage</code> is defined prior to any action that depends on it:</p> <pre><code>if (typeof localStorage !== 'undefined') { var x = localStorage.getItem('mod'); } else { // localStorage not defined } </code></pre> <p><strong>UPDATE:</strong></p> <p>If you need to validate that the feature is there and that it is also not turned off, you have to use a safer approach. To be perfectly safe:</p> <pre><code>if (typeof localStorage !== 'undefined') { try { localStorage.setItem('feature_test', 'yes'); if (localStorage.getItem('feature_test') === 'yes') { localStorage.removeItem('feature_test'); // localStorage is enabled } else { // localStorage is disabled } } catch(e) { // localStorage is disabled } } else { // localStorage is not available } </code></pre>