2
JavaScript Type Coercion Output
intermediate
•
Output Predict
Completed
What is logged to the console by: `console.log("5" - 2 + "1")`?
Helpful Hint:
The minus operator coerces string to number ("5" - 2 = 3), while the plus operator with a string concatenates (3 + "1" = "31").
Expected Solution:
31
Explanation: "5" - 2 evaluates to numeric 3. Then 3 + "1" performs string concatenation yielding "31".
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php