What is the difference between the following two snippets of code? Is the square bracket syntax an old, deprecated syntax? When I first used localStorage, all the documentation I found definitely said to use the square bracket syntax, but now I can't find any documentation on it at all.
The documented syntax:
localStorage.setItem('hello', 'world');
localStorage.getItem('hello'); // world
The square bracket syntax:
localStorage.hello = 'world';
localStorage.hello; // world
This is what the documentation says about it:
Although the values can be set and read using the standard JavaScript property access method, using the getItem and setItem methods is recommended.
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