JavaScript Advanced Practice
51 questions covering 9 JavaScript topics.
Quick Quiz
1. How do you call a static method named createGuest() defined on a class named User?
2. What symbol is used to declare a private field in a class?
3. What happens if you try to access a private field from outside the class that declares it?
4. What is the purpose of a getter in a class?
5. In the Temperature class example, why does temp.celsius = "hot" throw an error?
6. Which state indicates a Promise has not yet completed?
7. What do the two arguments passed to the Promise constructor executor do?
8. What is the main risk of forgetting to return a promise inside a .then() callback?
9. How does Promise.all() differ from Promise.allSettled()?
10. Which combinator is best suited for implementing a request timeout?
11. What does this code log?
Promise.resolve(1)
.then((value) => {
console.log(value);
return value + 1;
})
.then((value) => {
console.log(value);
});12. What does this code log?
Promise.reject("Error!")
.then(() => console.log("resolved"))
.catch((err) => console.log("caught:", err));13. What does an async function always return?
14. What happens when you await a rejected promise inside a try block?
15. Why does awaiting three independent promises one at a time run slower than necessary?
16. How do you run several independent async operations in parallel and await all their results?
17. Where is top-level await supported?
18. What does this code log?
async function getValue() {
return 5;
}
console.log(getValue());19. In what order does this code log?
async function run() {
console.log("A");
await null;
console.log("B");
}
console.log("start");
run();
console.log("end");20. Which flag makes a regex find all matches instead of stopping at the first one?
21. What does \d match?
22. What does test() return?
23. How do you access a named capture group called "year" from a match result?
24. What happens if you call replaceAll() with a regex that lacks the g flag?
25. What must an object have to satisfy the iterator protocol?
26. What makes an object usable with for...of?
27. What keyword pauses execution inside a generator function?
28. What happens when you call a generator function?
29. What happens to the value passed to gen.next(value)?
30. Event delegation relies on which DOM behavior?
31. In a delegated click listener attached to a <ul>, which property tells you the exact element that was clicked?
32. What does element.closest(".item") do?
33. Why does a delegated listener automatically handle elements added to the list after the listener was attached?
34. Which of these events would NOT be reliably handled by a delegated listener on an ancestor?
35. What happens when you access a property on an object that doesn't have it as an own property?
36. Which of these is the standard, modern way to read an object's prototype?
37. Why is placing a method on Constructor.prototype more memory-efficient than assigning it inside the constructor?
38. What does Object.create(proto) do?
39. What does the instanceof operator actually check?
40. What does this code log?
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function () {
return `${this.name} makes a noise.`;
};
const dog = new Animal("Rex");
console.log(dog.speak());
console.log(dog.hasOwnProperty("speak"));41. How many call stacks does JavaScript have?
42. Where does a setTimeout callback go once its timer expires?
43. Which of these lands on the microtask queue?
44. In what order does the event loop process pending work?
45. What logs first in: console.log("A"); setTimeout(() => console.log("B"), 0); Promise.resolve().then(() => console.log("C")); console.log("D");
46. In what order does this code log?
console.log("start");
setTimeout(() => console.log("timeout"), 0);
Promise.resolve()
.then(() => console.log("promise 1"))
.then(() => console.log("promise 2"));
console.log("end");