- Three type of storages have own Life time duration, memory sizes and control points. 2.Additionally if we should save Object, Array or such kind of Data bases, Firstly we change them to string via JSON KEYS like this.
const person={
name:"John",
age:21,
job:"Programmer",
hobby:['sleeping']
};
LocalStorage.setItem('person', JSON.stringify('person'))
LocalStorage
LocalStorage is controled only by client-side, limit of memory is 5/10mb it depends on the browser,it only supports the type of string data base and it could edit by users.
LocalStorage used with these keys:
- setItem -> Add
LocalStorage.setItem('name', 'John');
- getItem -> Value
let person=LocalStorage.getItem('name');
console.log(person);
- removeItem -> remove
LocalStorage.removeItem('person');
- clear -> clear the full storage
LocalStorage.clear();
Cookies
Cookies more used for Safty and it only save a few dates arround 4kb, if we want to delete it we can but other case it is not deleted. Cookies controlled by both side it client-side and server-side and it accept requests also supports string and editable.
Session
Sessin can save 5mb memory size , it removed when we close the tab and it also support string and controlled by client-side.
Top comments (3)
greatππ
Thanks bro your comments are forced me to type more than previous one
Just a heads up that you can add highlighting to the code blocks if you'd like. Just change:
... to specify the language:
More details in our editor guide!