localStorage

🧸 zelly log·2022년 5월 9일
1
post-thumbnail

MDN DOCS

Storage 객체에 접근해서 데이터를 저장하여 브라우저 세션 간에 공유할 수 있다.

localStorage : 저장한 데이터가 만료되지 않는다.
sessionStorage : 페이지 세션이 끝날 때 (페이지를 닫을 때) 사라진다.

myStorage = window.localStorage; //구문
localStorage.setItem('myCat', 'Tom'); // 추가
const cat = localStorage.getItem('myCat'); //읽기
localStorage.removeItem('myCat'); //제거
localStorage.clear(); //전체 제거
profile
🌱 Frontend Developer / ✏Studying / 🍋 React Typescript / 성장하는 프론트엔드 개발자!

0개의 댓글