문제 설명
값이 없는 경우 HTML5 로컬 저장소 개체는 무엇을 반환합니까? (What does the HTML5 Local Storage object return if there is no value?)
키/값 쌍이 이미 로컬 저장소 개체에 존재하는지 확인하는 함수를 작성할 때 무엇을 확인해야 합니까? 그러한 키/값 쌍이 없으면 null
, 빈 객체, 다른 것을 반환합니까?
참조 솔루션
방법 1:
localStorage.getItem
will return null
for keys that are unset:
The getItem(key) method must return the current value associated with the given key. If the given key does not exist in the list associated with the object then this method must return null.
Source: https://html.spec.whatwg.org/multipage/webstorage.html#dom‑storage‑getitem
(by Peter David Carter、Wander Nauta)