Page 1 of 1

Quick Question on localStorage -- boolean types

Posted: Fri Feb 06, 2015 9:54 pm
by Bruce Stuart

Just a quick question on localStorage data types --- especially at least for today - boolean.

I declare a localStorage var - in the builder to be of type boolean - let's say I call it 'LPaid' to track whether or not the product for sale - is the paid version or not.

I move the Javascript constant true to it by an assignment:

localStorage.setItem('LPaid', true);

I ask it back what the value is :

localStorage.getItem('LPaid');

it returns "true" (in quotes --- starting to officially confuse me).

So - I ask:

localStorage.getItem('LPaid") === true

of course this returns false .....

So - this is a bit of a conundrum - why in the builder to we get to declare certain things as say array or logical data types - when in the end - they are really just stored and returned as Strings ???

I know how to 'deal' with the confusion - but can you explain why it's this way possibly?

Happy Friday and thanks,
Bruce