Difference between using localStorage.getItem/setItem and new Storage().set/get?


Currently using localStorage.getItem/setItem, I’m wondering if it’s worthwhile to switch to http://ionicframework.com/docs/v2/api/platform/storage/LocalStorage/

The native APIs are more straight forward, localStorage.get(‘key’) returns the value if exists while new Storage().get() returns a promise which could be an overhead.

What’s the benefit to use new Storage() there?

1 Like

I would say that the promise represents less overhead, because it doesn’t stop the world. However, that’s not the main reason I would use the Storage API: that would be because you could seamlessly decide later to use a different backend (like sqlite) without having to change any client code.