localStorage和sessionStroage
localStorage
sessionStroage
增改
localStorage.setItem("name", "老王");
localStorage.age = 18;
localStorage["gender"] = "M";
查
localStorage.getItem("name");
localStorage.age
localStorage["gender"]
遍历
key(index):遍历所有的key
for (let i = 0; i < localStorage.length; i++) {
console.log(localStorage.getItem(localStorage.key(i)));
}
删
localStorage.removeItem("name");
清除
localStorage.clear();
cookie与localStorage和sessionStorage的异同
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/abfbb3ca0bfdcf484102c99994390c99.png)
instanceof与typeof得区别
同
都是用来判断一个变量得数据类型
异
typeof返回字符串,为变量得数据类型,number/string/boolean/undefined/null/object
返回布尔值,判断一个变量是否属于某个对象得实例