ALL


  Why localStorage only allows to store string values

localStorage allows data to be stored in browsers across sessions, the data will be there even though the session is expired. It is frequently used to store static data so that they can be loaded when needed. But as per spec, it says that the keys and the values are always strings (note that, as with objects, integer keys will be automatically converted to strings). Why cannot store the object as it is?Take a look at an example:var str = "test";localStorage.setItem("str", str);console.log(localStorage.getItem("str"));var obj = { a: "hello", b: 10};localStorage.setItem("obj", ob...

11,440 0       LOCALSTORAGE JAVASCRIPT