javascript - localStorage and boolean 'string' -


storing boolean value in localstorage, value converted string. trying converting value localstorage boolean, need use json.parse() method, more handy !! doesn't work.

code sample:

var test = false; localstorage['test'] = test; console.log("json.parse returns: ", json.parse(localstorage['test']), "expected: ", test); console.log("'!!' returns: ", !! localstorage['test'], "expected: ", test); 

-jsfiddle-

i'm quite confused why behaviour. explaination?

ps: using getter/setter localstorage methods doesn't matter here, same result.

local storage stores strings , i'm afraid, whatever input (if feed object, converted automatically standard tostring() method)... you're doing !! test on string, true.

you should use json.stringify() , json.parse() when dealing store in dom storage


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -