When saving values in localStorage those values are saved as string. There are some guidelines when checking for undefined vs. null.
Checking localStorage.variableName === undefined is the way to checked it.
Checking getItem("variableName") === null is the way to go.
Here is a sample and results in the console.
function testLocalStorage()
{
console.log('TESTING localStorage.value1')
if (localStorage.value1 === undefined)
console.log('localStorage.value1 - is undefined');
if (localStorage.value1 === null)
console.log('localStorage.value1 - is null');
console.log('\n');
console.log('TESTING getItem("value2")');
var licValue = localStorage.getItem("value2");
if(licValue === undefined)
console.log('getItem(localStorage.value2) - is undefined');
if(licValue === null)
console.log('getItem(localStorage.value2) - is null');
}
*** CONSOLE RESULTS ***
TESTING localStorage.value1
localStorage.value1 - is undefined
TESTING getItem("value2")
getItem(localStorage.value2) - is null