How best to work with localStorage?

localStorage.getItem('item') or localStorage.item
localStorage.setItem('item', 'blablabla) or localStorage.item = 'blablabla'
April 4th 20 at 13:11
3 answers
April 4th 20 at 13:13
You can read here.
If too lazy to read

const key = 'length';

localStorage[key] = 100;

console.log(localStorage[key]); // 0
console.log(localStorage.getItem(key)); // null

const key = 'length';

localStorage.setItem(key, 100);

console.log(localStorage[key]); // 1
console.log(localStorage.getItem(key)); // 100 (string)

April 4th 20 at 13:15

Note: It's recommended to use the Web Storage API (setItem, getItem, removeItem, key, length) to prevent the pitfalls associated with using plain objects as key-value stores.
April 4th 20 at 13:17
How to work better with storage?

After reading the documentation

Find more questions by tags JavaScript