Deleting from localStorage: should I use delete or .removeItem?

Google ChromeLocal Storage

Google Chrome Problem Overview


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.

Google Chrome Solutions


Solution 1 - Google Chrome

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex ChurchillView Question on Stackoverflow
Solution 1 - Google ChromeNathan BubnaView Answer on Stackoverflow