LearnFrenzy
Sign in Take a free test

Arrow Functions · Predict the Output · Question 14

An arrow returning a nested ternary Answer, explanation & discussion

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

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

main.js
const grade = (m) => (m >= 90 ? "A" : m >= 60 ? "B" : "C");
console.log([95, 72, 40].map(grade).join(""));
  • A ABC Correct
  • B AAB
  • C CBA
  • D ABB
Correct Answer: Option A

The whole ternary is one expression, so the arrow returns it implicitly; map passes each mark to grade.

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