Browser APIs & Storage — Series 3

Preview — 3 of 10 questions

What is logged?

javascript
localStorage.setItem('count', 5);
localStorage.setItem('flag', false);

console.log(
  typeof localStorage.getItem('count'),
  localStorage.getItem('count') + 1,
  localStorage.getItem('flag') === false,
  Boolean(localStorage.getItem('flag')),
);
Anumber 6 true false
Bstring 51 false true
Cstring 6 false false
Dnumber 6 false true

Which statement is correct?

AAll three are sent to the server on every request; only their expiry differs.
BsessionStorage is shared across all tabs of the same origin; localStorage is per-tab.
ClocalStorage expires when the browser closes; sessionStorage persists indefinitely.
DlocalStorage persists until it is cleared and is shared across tabs of the origin; sessionStorage is scoped to one tab and cleared when it closes; cookies are the only one automatically sent with requests.

What is logged?

javascript
console.log(localStorage.getItem('missing'), JSON.parse(localStorage.getItem('missing')));

try {
  JSON.parse(undefined);
} catch (e) {
  console.log(e.constructor.name);
}
Anull null then SyntaxError
Bundefined undefined then TypeError
Cnull then SyntaxError then SyntaxError
Dnull null then nothing — JSON.parse(undefined) returns undefined

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.