Question 11
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const latest = "10.2";
const installed = "9.8";
console.log(latest > installed ? "Update available" : "Up to date");
- A > cannot compare strings
- B The ternary is reversed
- C Version strings must not contain dots
- D The versions are compared as strings, and "1" < "9" decides it – compare the parts as numbers Correct
Correct Answer: Option D
String comparison looks only at the first differing character. Split and compare numerically: const [a, b] = latest.split(".").map(Number); … (or localeCompare with { numeric: true }).
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!