For function* g() { yield 1; return 2; }, what is [...g()]?
return produces { value: 2, done: true }, and consumers such as spread and for…of stop when done is true without using that value.
ES6 Features · Exercise 1 of 4
Fifteen multiple-choice questions on ES6 and modern JavaScript: classes, super, private and static members, Map, Set and WeakMap, Symbol, the iteration protocol, generators and modules. Pick an option to check your answer instantly.
For function* g() { yield 1; return 2; }, what is [...g()]?
return produces { value: 2, done: true }, and consumers such as spread and for…of stop when done is true without using that value.
A module has export default function main() {} and export const VERSION = 2;. Which import is correct?
The default export is imported without braces and may get any name; named exports go in braces with their exported names.
Which statement about ES modules is true?
Modules are strict, have module scope, are deferred by default in browsers and are evaluated once even if imported many times.
An object has a property with a Symbol key. Where does that key appear?
Symbol-keyed properties are deliberately hidden from the usual enumeration, which makes them good for metadata. obj[sym] still reads them.
Which two rules apply to class declarations but not to function declarations?
Classes behave like let for hoisting, and calling them without new throws "Class constructor … cannot be invoked without 'new'". Their bodies are also always strict.
Timed online tests with instant scores and explanations.