All quizzesHard
Advanced Patterns — Series 2
Preview — 3 of 10 questions
What is the output of the following code?
javascript
const obj = { value: 42 };
const { value: x = 10, label: y = 'default' } = obj;
console.log(x, y);A42 undefined
B42 'default'
C10 'default'
DReferenceError
What will the following code log?
javascript
function makeCounter() {
let count = 0;
return {
inc() { count++; },
get() { return count; },
};
}
const a = makeCounter();
const b = makeCounter();
a.inc(); a.inc();
b.inc();
console.log(a.get(), b.get());A2 1
B3 3
C2 2
D1 1
What is logged?
javascript
const arr = [1, 2, 3];
const [first, ...rest] = arr;
rest.push(4);
console.log(arr, rest);A[1, 2, 3, 4] and [2, 3, 4]
B[1, 2, 3] and [2, 3, 4]
C[1, 2, 3] and [2, 3]
D[1, 2, 3, 4] and [2, 3]
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.