Modern JavaScript quiz

  • Admin
  • 1 min read

Nine questions on destructuring, spread, array methods, modules and classes.

JavaScript

Modern JavaScript quiz

9 questions, instant feedback

Question 1 of 9
Question 1 of 9 Which line extracts name from an object?
Why this is the answer

Object destructuring uses braces and matches property names. Square brackets destructure arrays by position.

Question 2 of 9
Question 2 of 9 What does [...items] create?
Why this is the answer

Spread copies the top level. Nested objects are still shared, which is why deep updates need care.

Question 3 of 9
Question 3 of 9 Which method returns a new array of transformed items?
Why this is the answer

map returns one new value per item. forEach returns undefined and is for side effects.

Question 4 of 9
Question 4 of 9 Which method keeps only items that pass a test?
Why this is the answer

filter returns a new array containing the items for which the callback returned true.

Question 5 of 9
Question 5 of 9 What does reduce need besides a callback?
Why this is the answer

The accumulator starts from the initial value you pass. Without one, the first item becomes the initial accumulator and empty arrays throw.

Question 6 of 9
Question 6 of 9 Which syntax imports a named export?
Why this is the answer

Named exports are imported with braces. A default export uses the form without braces.

Question 7 of 9
Question 7 of 9 What is a class constructor for?
Why this is the answer

The constructor runs on new and sets up the instance. Methods live on the prototype and are shared.

Question 8 of 9
Question 8 of 9 What does user?.name do when user is null?
Why this is the answer

Optional chaining short-circuits and returns undefined instead of throwing on null or undefined.

Question 9 of 9
Question 9 of 9 Which operator falls back only for null or undefined?
Why this is the answer

?? uses the right side only for null or undefined. || also falls back for 0, empty string and false.

Your answers stay in this browser. Nothing is sent to a server.