I'm using localStorage
in a Chrome extension.
Is there any difference between delete localStorage[key]
and window.localStorage.removeItem(key)
or do they behave identically?
Note that I choose window.localStorage.removeItem(key)
to correspond exactly to the spec, but localStorage.removeItem(key)
is how it would probably look in the wild.
getItem() : This is how you get items from localStorage. removeItem() : Remove an item by key from localStorage. clear() : Clear all localStorage. key() : Passed a number to retrieve the key of a localStorage.
User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user. User agents should always avoid deleting data while a script that could access that data is running.
There's no difference in Chrome, but i recommend using localStorage.removeItem(key) so that you get in the habit of doing so. That way, when you go to use localStorage in a website, you are already using the method that is most likely to work with shims and polyfills for outdated browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With