Multiple choice practice

ES6+ MCQ questions

Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.

Questions
84
From lessons
64
Your last test
—

Practice test

ES6+ practice testTrue or false Question 1 of 10

A rest parameter is a real array with map, filter and reduce.

Score so far: 0/0

All questions with answers

  1. Which ECMAScript edition is commonly called ES6?

    • AES2009
    • BES2015
    • CES2016
    • DES2020
    Show answer

    Answer: B. ES2015

    ES6 is ECMAScript 2015; editions have been yearly since.

  2. What is logged?

    JavaScript Illustrative
    const n = 1;
    n = 2;
    console.log(n);
    
    • A1
    • B2
    • CTypeError
    • Dundefined
    Show answer

    Answer: C. TypeError

    Reassigning a const binding throws “Assignment to constant variable”.

  3. What does this arrow function return?

    JavaScript Illustrative
    const make = () => { id: 1 };
    
    • AAn object { id: 1 }
    • Bundefined
    • C1
    • DA syntax error
    Show answer

    Answer: B. undefined

    Braces start a function body with a label “id”. Wrap the object in parentheses: () => ({ id: 1 }).

  4. What does `Total: ${2 + 3}` produce?

    • A"Total: 2 + 3"
    • B"Total: 5"
    • C"Total: ${5}"
    • DAn error
    Show answer

    Answer: B. "Total: 5"

    Expressions inside ${} are evaluated and converted to strings.

  5. What does const [a, ...rest] = [1, 2, 3] give rest?

    • A2
    • B[2, 3]
    • C[1, 2, 3]
    • D3
    Show answer

    Answer: B. [2, 3]

    The rest element collects the remaining items into an array.

  6. Which syntax merges two objects into a new one?

    • AObject.merge(a, b)
    • B{ ...a, ...b }
    • Ca + b
    • D[...a, ...b]
    Show answer

    Answer: B. { ...a, ...b }

    Object spread copies own enumerable properties; later ones win.

  7. What does Math.max(...[4, 9, 2]) return?

    • A[4, 9, 2]
    • B9
    • CNaN
    • D4
    Show answer

    Answer: B. 9

    Spread passes array items as separate arguments.

  8. Which keyword calls the parent constructor in a class?

    • Aparent()
    • Bbase()
    • Csuper()
    • Dthis.parent()
    Show answer

    Answer: C. super()

    super() must be called before using this in a derived constructor.

  9. What does user?.address?.city return if user is null?

    • Anull
    • Bundefined
    • CTypeError
    • D""
    Show answer

    Answer: B. undefined

    Optional chaining short-circuits to undefined.

  10. What does 0 ?? 5 evaluate to?

    • A5
    • B0
    • Cnull
    • Dundefined
    Show answer

    Answer: B. 0

    ?? only falls back for null or undefined; 0 is kept.

  11. What does new Set([1, 1, 2]).size return?

    • A3
    • B2
    • C1
    • Dundefined
    Show answer

    Answer: B. 2

    A Set stores unique values only.

  12. Which keys can a Map use?

    • AStrings only
    • BStrings and symbols
    • CAny value, including objects
    • DNumbers only
    Show answer

    Answer: C. Any value, including objects

    Map keys can be any type and are compared with SameValueZero.

  13. What does a generator function return when called?

    • AIts first yielded value
    • BAn iterator object
    • CA promise
    • Dundefined
    Show answer

    Answer: B. An iterator object

    Calling it does not run the body; it returns a generator you drive with next().

  14. What does Symbol("id") === Symbol("id") evaluate to?

    • Atrue
    • Bfalse
    • CTypeError
    • Dundefined
    Show answer

    Answer: B. false

    Every Symbol() call creates a unique value; use Symbol.for for shared ones.

  15. Which export can be imported with any name and without braces?

    • AA named export
    • BA default export
    • CA namespace export
    • DA re-export
    Show answer

    Answer: B. A default export

    import anything from "./file.js" receives the default export.

  16. What does import("./chart.js") return?

    • AThe module object directly
    • BA promise of the module
    • Cundefined
    • DA string path
    Show answer

    Answer: B. A promise of the module

    Dynamic import is asynchronous and returns a promise.

  17. Which method returns the last element of an array?

    • Aarr.last()
    • Barr.at(-1)
    • Carr[-1]
    • Darr.end()
    Show answer

    Answer: B. arr.at(-1)

    at() accepts negative indexes; arr[-1] reads a property named "-1".

  18. Which method sorts without changing the original array?

    • Asort()
    • BtoSorted()
    • Corder()
    • Dsorted()
    Show answer

    Answer: B. toSorted()

    toSorted (ES2023) returns a new sorted array.

  19. What is logged?

    JavaScript Illustrative
    function greet(name = 'guest') { return name; }
    console.log(greet(null));
    
    • Aundefined
    • B"guest"
    • Cnull
    • D""
    Show answer

    Answer: C. null

    Default parameters only apply for undefined, so null is passed through.

  20. What does Object.entries({ a: 1 }) return?

    • A["a", 1]
    • B[["a", 1]]
    • C{ a: 1 }
    • D["a"]
    Show answer

    Answer: B. [["a", 1]]

    An array of [key, value] pairs, which pairs well with for…of and Object.fromEntries.

  21. What is logged?

    JavaScript Illustrative
    const { a = 1, b = 2 } = { a: null };
    console.log(a, b);
    
    • A1 2
    • Bnull 2
    • Cundefined 2
    • Dnull null
    Show answer

    Answer: B. null 2

    Defaults only replace undefined. a is null, so it stays null; b is missing, so it defaults to 2.

    From the lesson: Destructuring
  22. What is logged?

    JavaScript Illustrative
    console.log(0 ?? 5, 0 || 5);
    
    • A0 0
    • B5 5
    • C0 5
    • D5 0
    Show answer

    Answer: C. 0 5

    ?? only replaces null/undefined, so 0 stays. || replaces any falsy value.

    From the lesson: Optional Chaining
  23. ES6 is another name for…

    • AES2009
    • BES2015
    • CES2020
    • DTypeScript
    Show answer

    Answer: B. ES2015

    ES6 was officially renamed ECMAScript 2015.

    From the lesson: Introduction to ECMAScript
  24. Which committee decides new JavaScript features?

    • AW3C
    • BWHATWG
    • CTC39
    • DNode.js Foundation
    Show answer

    Answer: C. TC39

    TC39 (Ecma Technical Committee 39) maintains ECMAScript.

    From the lesson: Introduction to ECMAScript
  25. async/await was introduced in ES2015.

    • ATrue
    • BFalse
    Show answer

    Answer: B. False

    async/await arrived in ES2017. ES2015 introduced promises.

    From the lesson: Introduction to ECMAScript