Single Choice Question

  1. What is the difference between local storage and session storage?
    1. Local storage is persistent, session storage is not.
    2. Local storage is not persistent, session storage is persistent.
    3. Local storage is persistent, session storage is persistent.
    4. Local storage is persistent, session storage is persistent.
  2. The method to get the value of a cookie is 有问题
    1. getCookie() 来自notes
    2. getCookies()
    3. getCookieValue()
    4. getCookieName()
  3. The content of cookie used to specify the date and time when the cookie is out of date is
    1. expires
    2. expire
    3. max-age
    4. path
  4. To save lots of data in the browser, which of the following is the best way to be used?
    1. localStorage
    2. sessionStorage
    3. cookie
    4. indexedDB

True or False Question

  1. The cookie is used to store data in the browser.
    True
  2. The local storage is persistent, session storage is not.
    True
  3. When the user closes the browser, the data in the cookie will be lost.
    False

Definition of Term

  1. Cookie Small strings of data that are stored in the browser
  2. Local Storage 用于在浏览器中长期保存键值对数据。
  3. Session Storage 用于在浏览器中临时保存数据,生命周期为当前会话。
  4. IndexedDB IndexedDB 是一种浏览器提供的本地数据库系统,允许开发者以对象的形式存储大量结构化数据。

Short Answer

  1. What are the differences between local storage and session storage?
    localStorage生命周期永久,同一源(域+协议+端口)下的所有标签页共享,而SessionStorage生命周期只在当前标签页,且仅当前标签页有效,
  2. Try to compare cookie with storage?
    cookie容量小,每次请求时自动发送到服务器,生命周期可以自定义,使用场景例如用户登录;
    LocalStorage/SessionStorage: 容量大于cookie,仅在本地浏览器使用,使用场景例如本地数据缓存