All quizzesHard
Engine-Level Behaviour
Preview — 3 of 10 questions
What is the output?
javascript
Promise.resolve()
.then(() => {
console.log(1);
return Promise.resolve(2);
})
.then((v) => console.log(v));
Promise.resolve()
.then(() => console.log(3))
.then(() => console.log(4));A1 2 3 4
B1 3 4 2
C1 3 2 4
D3 1 4 2
What is the output?
javascript
const obj = {
[Symbol.toPrimitive](hint) {
if (hint === "number") return 42;
if (hint === "string") return "hello";
return true;
},
};
console.log(+obj);
console.log(`${obj}`);
console.log(obj + "");A42 "hello" "true"
B42 "hello" "42"
CNaN "hello" "true"
D42 "[object Object]" "true"
What is guaranteed about this code's output?
javascript
let obj = { name: "target" };
const ref = new WeakRef(obj);
console.log(ref.deref()?.name);
obj = null;
// GC may or may not have run here
console.log(ref.deref()?.name);A"target" then "target" always
B"target" then undefined always
C"target" then either "target" or undefined
Dundefined then undefined
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.