One of the first results from a Google search says that this syntax is to be used for localStorage:
localStorage.lastname="Smith";
MDN uses .setItem() and .getItem(), I suppose so that if the browser doesn't support localStorage, then you can add it using the technique defined there.
But since my program is only running on iOS, I guess my question is:
Is it ok to use
localStorage.lastname="Smith";
instead of:
window.localStorage.setItem("lastname","Smith");
Though both methods are valid JavaScript,
localStorage.lastName = "Smith";
assigning a value directly like above to a key can sometimes result in property conflicts.
window.localStorage.setItem("lastname","Smith");
On the other hand is a better practice to get into. MDN and most other resources recommend this method when working with Local-storage.
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