LearnFrenzy
Sign in Take a free test

Arrow Functions · Predict the Output · Question 15

An immediately invoked arrow Answer, explanation & discussion

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

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

main.js
const result = ((x) => x * 3)(7);
const config = (() => ({ mode: "prod", debug: false }))();
console.log(result, config.mode);
  • A 7 prod
  • B 21 undefined
  • C SyntaxError
  • D 21 prod Correct
Correct Answer: Option D

Wrapping an arrow in parentheses and calling it immediately works like an IIFE.

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