LearnFrenzy
Sign in Take a free test

Arrow Functions · Predict the Output · Question 16

A comma in an implicit return Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 16 Back to Exercise

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

main.js
const f = () => (console.log("side effect"), 42);
console.log(f());
  • A 42 side effect
  • B 42
  • C side effect 42 Correct
  • D undefined
Correct Answer: Option C

The comma operator evaluates the log first and then returns 42, which the outer console.log prints.

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