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? JScript ECMAScript Java TypeScript JavaScript is standardized by Ecma International as ECMAScript. (Chapter 1: Get started )
2. Can you push to an array declared with const? Yes, the array can change; only reassigning the name is blocked. No, const arrays are frozen. Only in strict mode. Only once. const protects the binding, not the contents of the object. (Chapter 2: let, const and var )
3. What does Number("12px") return? 12 NaN "12" 0 Number() requires the whole string to be numeric; parseInt would return 12. (Chapter 3: Data types )
4. What does 1 === "1" return? true false "1" An error 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? "x-b-x" "x-b-a" "a-b-x" "xbx" 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? Total: ${n} The value of n An error Total: Only backtick strings interpolate; in quotes, ${n} is ordinary text. (Chapter 6: Template literals )
7. What happens if a switch case has no break? An error is thrown. Execution continues into the next case. The switch restarts. Only that case runs. 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? Its values Its property names (keys) Its methods only Nothing; it only works on arrays 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)? 3 [2, 3] [1, 2, 3] 2 The rest parameter collects the arguments after a into an array. (Chapter 9: Functions )
10. Why does () => { x: 1 } return undefined? The braces are treated as a function body, not an object. Arrows cannot return objects. x is undefined. It needs the function keyword. Wrap the object in parentheses: () => ({ x: 1 }). (Chapter 10: Arrow functions )
11. What does pop() return? The new length The removed last item The array without its last item undefined always pop removes the last item and returns it. (Chapter 11: Arrays )
12. What does [5, 12, 8].filter((n) => n > 6) return? [5] [12, 8] true 12 filter keeps every item for which the callback returns true. (Chapter 12: map, filter, reduce )
13. What does ({}).missing return? null undefined A TypeError false Reading a missing property gives undefined. (Chapter 13: Objects )
14. What does const { a: b } = { a: 5 }; create? A variable a equal to 5 A variable b equal to 5 A variable b equal to "a" Nothing; it is invalid a: b reads property a into a variable named b. (Chapter 14: Destructuring and spread )
15. Where can a #private field be accessed? Anywhere through the instance Only inside the class body Only in subclasses Only through Object.keys Private fields are only reachable by code in the class that declares them. (Chapter 15: Classes )
16. Which error does reading null.length produce? TypeError ReferenceError SyntaxError RangeError Reading a property of null is a type misuse. (Chapter 16: Errors and try...catch )
17. What does Promise.all resolve with? The first result An array of results in the original order The fastest result undefined Results keep the order of the input array. (Chapter 17: Promises )
18. What happens when an awaited promise rejects? await returns undefined. An error is thrown at the await, which try...catch can handle. The program exits. It retries automatically. A rejection becomes a thrown error at the await point. (Chapter 18: async and await )
19. Which string is valid JSON? {name: "Ava"} {'name': 'Ava'} {"name": "Ava"} {"name": "Ava",} JSON requires double-quoted keys and strings and forbids trailing commas. (Chapter 19: JSON )
Check answers
← Back to the JavaScript tutorial