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
A rest parameter is a real array with map, filter and reduce.
All questions with answers
Which ECMAScript edition is commonly called ES6?
Show answer
Answer: B. ES2015
ES6 is ECMAScript 2015; editions have been yearly since.
What is logged?
JavaScript Illustrative const n = 1; n = 2; console.log(n);Show answer
Answer: C. TypeError
Reassigning a const binding throws “Assignment to constant variable”.
What does this arrow function return?
JavaScript Illustrative const make = () => { id: 1 };Show answer
Answer: B. undefined
Braces start a function body with a label “id”. Wrap the object in parentheses: () => ({ id: 1 }).
What does `Total: ${2 + 3}` produce?
Show answer
Answer: B. "Total: 5"
Expressions inside ${} are evaluated and converted to strings.
What does const [a, ...rest] = [1, 2, 3] give rest?
Show answer
Answer: B. [2, 3]
The rest element collects the remaining items into an array.
Which syntax merges two objects into a new one?
Show answer
Answer: B. { ...a, ...b }
Object spread copies own enumerable properties; later ones win.
What does Math.max(...[4, 9, 2]) return?
Show answer
Answer: B. 9
Spread passes array items as separate arguments.
Which keyword calls the parent constructor in a class?
Show answer
Answer: C. super()
super() must be called before using this in a derived constructor.
What does user?.address?.city return if user is null?
Show answer
Answer: B. undefined
Optional chaining short-circuits to undefined.
What does 0 ?? 5 evaluate to?
Show answer
Answer: B. 0
?? only falls back for null or undefined; 0 is kept.
What does new Set([1, 1, 2]).size return?
Show answer
Answer: B. 2
A Set stores unique values only.
Which keys can a Map use?
Show answer
Answer: C. Any value, including objects
Map keys can be any type and are compared with SameValueZero.
What does a generator function return when called?
Show answer
Answer: B. An iterator object
Calling it does not run the body; it returns a generator you drive with next().
What does Symbol("id") === Symbol("id") evaluate to?
Show answer
Answer: B. false
Every Symbol() call creates a unique value; use Symbol.for for shared ones.
Which export can be imported with any name and without braces?
Show answer
Answer: B. A default export
import anything from "./file.js" receives the default export.
What does import("./chart.js") return?
Show answer
Answer: B. A promise of the module
Dynamic import is asynchronous and returns a promise.
Which method returns the last element of an array?
Show answer
Answer: B. arr.at(-1)
at() accepts negative indexes; arr[-1] reads a property named "-1".
Which method sorts without changing the original array?
Show answer
Answer: B. toSorted()
toSorted (ES2023) returns a new sorted array.
What is logged?
JavaScript Illustrative function greet(name = 'guest') { return name; } console.log(greet(null));Show answer
Answer: C. null
Default parameters only apply for undefined, so null is passed through.
What does Object.entries({ a: 1 }) return?
Show answer
Answer: B. [["a", 1]]
An array of [key, value] pairs, which pairs well with for…of and Object.fromEntries.
What is logged?
JavaScript Illustrative const { a = 1, b = 2 } = { a: null }; console.log(a, b);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: DestructuringWhat is logged?
JavaScript Illustrative console.log(0 ?? 5, 0 || 5);Show answer
Answer: C. 0 5
?? only replaces null/undefined, so 0 stays. || replaces any falsy value.
From the lesson: Optional ChainingES6 is another name for…
Show answer
Answer: B. ES2015
ES6 was officially renamed ECMAScript 2015.
From the lesson: Introduction to ECMAScriptWhich committee decides new JavaScript features?
Show answer
Answer: C. TC39
TC39 (Ecma Technical Committee 39) maintains ECMAScript.
From the lesson: Introduction to ECMAScriptasync/await was introduced in ES2015.
Show answer
Answer: B. False
async/await arrived in ES2017. ES2015 introduced promises.
From the lesson: Introduction to ECMAScript