Particularly for localStorage.foo
For Safari it is set to:
undefined
For Firefox it is set to:
null
Does anyone know the values for Chrome and IE?
Why is it different? Just random choices by browser programmers?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s always
undefined. Perhaps your observation method is what led you to believe the values are different in different browsers.Oh, I’ll qualify that statement for old versions of IE, which might do some other thing for all I know. I bet they use
undefinedalso.Ah – Mr. Protagonist has an interesting point. On any normal object, a non-existent property will be
null. However, Firefox does indeed seem to reportnullas the value of a non-existent property specifically oflocalStorage. Hmm… My vote would be that that’s a bug, but I’ll check the w3c spec (or proto-spec or whatever it is).The “value”
undefinedisn’t really a value; it’s more like the Buddhist mu — it’s kinda like saying, “what you asked for doesn’t make sense”. The valuenullin JavaScript is treated differently thanundefined. Thus:The variable “b” will be
undefined. It’s weird, but it lets you tell the difference between a property being present butnulland a property being missing. (Of course, theinoperator lets you figure that out too.)