LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 19

Destructuring pairs in callbacks Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
["a", "b"]
  .map((v, i) => [i, v])
  .forEach(([i, v]) => console.log(i + v));
  • A 1 1
  • B a0 b1
  • C 0 1
  • D 0a 1b Correct
Correct Answer: Option D

map builds [index, value] pairs and forEach destructures each pair in its parameter list. 0 + "a" concatenates.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links