Advanced Patterns — Series 3

Preview — 3 of 10 questions

What is the output of the following code?

javascript
const config = { server: { port: 8080 } };
const { server: { host = 'localhost', port } = {}, timeout = 30 } = config;

console.log(host, port, timeout);
Aundefined 8080 30
Blocalhost undefined 30
Clocalhost 8080 30
DTypeError: Cannot destructure property 'host' of undefined

What will the following code log?

javascript
function make() {
  let value = 'first';
  const read = () => value;
  value = 'second';
  return read;
}

console.log(make()());
Asecond
Bfirst
Cundefined
DReferenceError: value is not defined

What is logged?

javascript
const user = { id: 1, name: 'Ada', meta: { active: true } };
const { id, ...rest } = user;

rest.meta.active = false;

console.log(id, 'id' in rest, user.meta.active);
A1 true false
B1 true true
C1 false true
D1 false false

Sign up free to play

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