angular-local-storage icon indicating copy to clipboard operation
angular-local-storage copied to clipboard

get('nonExistingProperty') should return undefined, not null

Open raoel opened this issue 10 years ago • 2 comments
trafficstars

I think if a property does not exist, you should not return a value (null is an object in Javascript).

Also, I think it would be convenient to be able to see if a value exists in localStorage by calling a method like has('aProperty') that returns true or false. I know I could call keys() but that sounds like a workaround :-)

Thanks!

raoel avatar Aug 06 '15 08:08 raoel

Yeah, I second that. For instance, I store a boolean value in the session storage, but in case it isn't set, I'll use a default value. Problem is, I can't distinguish the 'false' value from a missing key. I could get the list of keys and check whether my key is contained in that list, but that seems a bit overkill. A has('aProperty') method would certainly help.

NikolajDL avatar Sep 05 '15 23:09 NikolajDL

This is actually the proper return for a native localStorage.getItem call when the key is undefined. While I agree that undefined makes more sense, I don't think we should alter expected behaviour.

grevory avatar Mar 17 '16 03:03 grevory