TetSharing

JavaScript final quiz

One question from each of the 19 chapters. Pick an answer for each, then press Check answers. Each explanation links back to the chapter it comes from, so you know exactly what to reread.

19 questions

1. What is the official name of the language standard behind JavaScript?

JavaScript is standardized by Ecma International as ECMAScript. (Chapter 1: Get started)

2. Can you push to an array declared with const?

const protects the binding, not the contents of the object. (Chapter 2: let, const and var)

3. What does Number("12px") return?

Number() requires the whole string to be numeric; parseInt would return 12. (Chapter 3: Data types)

4. What does 1 === "1" return?

Strict equality requires the same type, and these are a number and a string. (Chapter 4: Operators and equality)

5. What does "a-b-a".replace("a", "x") return?

replace with a string pattern changes only the first match. (Chapter 5: Strings)

6. What is printed by console.log("Total: ${n}") with double quotes?

Only backtick strings interpolate; in quotes, ${n} is ordinary text. (Chapter 6: Template literals)

7. What happens if a switch case has no break?

Without break, control falls through to the following case. (Chapter 7: if, else and switch)

8. What does for...in iterate over in an object?

for...in yields the enumerable property names as strings. (Chapter 8: Loops)

9. In function f(a, ...rest), what is rest for f(1, 2, 3)?

The rest parameter collects the arguments after a into an array. (Chapter 9: Functions)

10. Why does () => { x: 1 } return undefined?

Wrap the object in parentheses: () => ({ x: 1 }). (Chapter 10: Arrow functions)

11. What does pop() return?

pop removes the last item and returns it. (Chapter 11: Arrays)

12. What does [5, 12, 8].filter((n) => n > 6) return?

filter keeps every item for which the callback returns true. (Chapter 12: map, filter, reduce)

13. What does ({}).missing return?

Reading a missing property gives undefined. (Chapter 13: Objects)

14. What does const { a: b } = { a: 5 }; create?

a: b reads property a into a variable named b. (Chapter 14: Destructuring and spread)

15. Where can a #private field be accessed?

Private fields are only reachable by code in the class that declares them. (Chapter 15: Classes)

16. Which error does reading null.length produce?

Reading a property of null is a type misuse. (Chapter 16: Errors and try...catch)

17. What does Promise.all resolve with?

Results keep the order of the input array. (Chapter 17: Promises)

18. What happens when an awaited promise rejects?

A rejection becomes a thrown error at the await point. (Chapter 18: async and await)

19. Which string is valid JSON?

JSON requires double-quoted keys and strings and forbids trailing commas. (Chapter 19: JSON)

← Back to the JavaScript tutorial