Question 16
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const marks = 72;
const grade = marks >= 90 ? "A" : marks >= 75 ? "B" : marks >= 60 ? "C" : "D";
console.log(grade);
- A B
- B D
- C A
- D C Correct
Correct Answer: Option D
The ternary is right-associative, so the conditions are tested in order: 72 is not ≥ 90, not ≥ 75, but is ≥ 60.
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!