In the case that you are trying to get a local storage item that doesn\'t exist, is it possible to set a default value for that item?
For example, let\'s say that in
The solution from James:
var preference = localStorage.getItem('some-key') || 'Default Value';
Only works if you never save empty strings OR booleans OR if your variable can be 0.
Solution which is longer but always works:
var preference = localStorage.getItem('some-key');
if(null === preference)
{
preference = 'Default Value';
}