ES6+ Quiz - Languages JavaScript
Free practice quiz: ES6+ (Languages JavaScript). 56 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages JavaScript practice quiz has 56 multiple-choice questions on ES6+, and 56 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 56 questions, freeSample questions
Which of the following correctly declares a constant variable in JavaScript ES6?
Show answer
Answer: C. const PI = 3.14;
In ES6, the `const` keyword is used to declare variables whose values cannot be reassigned. `var` and `let` declare variables that can be reassigned, and `constant` is not a valid JavaScript keyword for variable declaration.
What does the `async` keyword in ES6 signify?
Show answer
Answer: C. It declares a function that implicitly returns a Promise
An `async` function always returns a Promise. If the function returns a non-Promise value, it's wrapped in a resolved Promise. If it throws an error, it returns a rejected Promise.
Consider the code: `let x = 10; function outer() { let x = 20; function inner() { console.log(x); } inner(); } outer();`. What is logged?
Show answer
Answer: B. 20
JavaScript uses lexical scoping. The `inner` function is within the scope of `outer`, which has its own `x` variable with the value `20`. Therefore, `inner` accesses `x` from `outer`'s scope, not the global scope.
What is the purpose of the `Symbol.iterator` method in ES6?
Show answer
Answer: A. To define how an object can be iterated over
The `Symbol.iterator` is a method that is called when a `for...of` loop or other iterable consumption methods are used on an object. It returns an iterator object, which implements the iterator protocol.
What is a WeakMap in ES6?
Show answer
Answer: B. A Map where keys are weakly held, allowing garbage collection if the key is no longer referenced elsewhere
Unlike a `Map`, keys in a `WeakMap` must be objects and are held weakly. If an object used as a key is garbage collected, the entry in the `WeakMap` is automatically removed.
More questions in this quiz
Answers and explanations are in the full quiz.
- What is the output of `console.log([...[1, 2], ...[3, 4]]);` in ES6?
- What does the arrow function `((a, b) => a + b)(5, 3)` return?
- Which statement correctly uses template literals in ES6?
- What is the purpose of the `let` keyword in ES6?
- Consider the following code: `const arr = [1, 2, 3]; const [a, b] = arr; console.log(a);`. What will be logged?
- What is a default parameter in JavaScript ES6?
- What does `const { name, age } = { name: 'Alice', age: 30 };` do?
- Which of the following is a valid ES6 class declaration?
- What is the output of `console.log(Promise.resolve(5))`?
- What is a generator function in ES6?
- What does the `await` keyword in ES6 do?
- What is a Symbol in ES6?
- What does the `Map` object in ES6 represent?
- What is the purpose of the `Set` object in ES6?
- What is the output of `console.log(String.fromCharCode(65))`?
- Which ES6 feature allows you to define a function that takes a variable number of arguments as an array?
- What is `Object.assign()` used for in ES6?
- What is the output of `console.log(Math.max(...[1, 5, 2]))`?
- Which of the following is NOT a new primitive type introduced in ES6?
- What is the difference between `Array.prototype.map()` and `Array.prototype.forEach()` in ES6?
- What does the `finally` block in a `try...catch...finally` statement do?
- What is the output of `console.log(typeof null)`?
- What is the primary benefit of using `const` over `let`?
- Which of these is NOT a valid way to create an object in JavaScript?
- What is the result of `console.log(2 + '3' * 2)`?
- Which ES6 feature is used to create promises that can be chained together?
- What is the primary difference between `let` and `var` regarding scope in ES6?
- What will `console.log('hello'.repeat(3))` output?
- Which ES6 method can be used to check if an array includes a certain element?
- What is the output of `console.log(0.1 + 0.2 === 0.3)`?
- What is the output of `const x = 10; if (true) { let x = 20; } console.log(x);`?
- Which of the following is an example of a default parameter in an ES6 arrow function?
- What is the difference between `Object.keys()` and `Object.values()` in ES6?
- What does the `entries()` method of a Map return in ES6?
- What is the result of `console.log('abc'.padStart(5, 'x'))`?
- Which ES6 feature is used to create a shallow copy of an array?
- What does the `for...of` loop iterate over in ES6?
- What is the purpose of `Object.entries()` in ES6?
- What is the output of `console.log(String.prototype.includes.call('JavaScript', 'Script'))`?
- What is a Proxy in ES6?
- What does the `Array.from()` method do in ES6?
- What is the primary purpose of the `Reflect` object in ES6?
- What does `const myString = 'Hello'; console.log(myString[0]);` output?
- Which ES6 feature provides a more direct way to handle promises than traditional callback chaining?
- What is the output of `console.log(typeof typeof 1);`?
- What does the `Object.getOwnPropertyDescriptor()` method return for a given property of an object?
- What is the result of `let a = [1, 2]; let b = a; b.push(3); console.log(a);`?
- Which ES6 feature allows for cleaner syntax for creating functions that return values when immediately invoked?
- What is the output of `console.log(typeof NaN)`?
- What does the `Array.prototype.fill()` method do in ES6?
- Which ES6 feature allows you to define a function that returns a Promise and can pause its execution until another Promise resolves?