All quizzesHard
Expert Mastery — Series 3
Preview — 3 of 10 questions
What is the output?
javascript
const target = { a: 1 };
const p = new Proxy(target, {
has(t, key) {
return key.startsWith('_') ? false : Reflect.has(t, key);
},
});
target._secret = 2;
console.log('a' in p, '_secret' in p, p._secret);Atrue true 2
Btrue false undefined
Ctrue false 2
DTypeError: 'has' on proxy: trap returned falsish
Which statement about WeakMap is correct?
AA WeakMap accepts primitive keys, and its entries disappear when memory runs low.
BWeakMap keys must be objects (or non-registered symbols) and are held weakly, so an entry becomes unreachable once nothing else references its key.
CWeakMap behaves exactly like Map but exposes size and can be iterated with for...of.
DA WeakMap holds its values weakly, so a value can vanish while its key is still reachable.
What does the following print?
javascript
function* inner() {
yield 1;
return 'ret';
}
function* outer() {
const r = yield* inner();
yield r;
}
console.log([...outer()]);A[1]
B[1, undefined]
C['ret']
D[1, 'ret']
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.