LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 16

Dividing numbers, including by zero 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
console.log(10 / 4);
console.log(10 / 0);
console.log(-10 / 0);
  • A 2.5 Infinity -Infinity Correct
  • B 2 Error Error
  • C 2.5 NaN NaN
  • D 2 Infinity -Infinity
Correct Answer: Option A

All numbers are 64-bit floating point, so 10 / 4 is 2.5 (no integer division). Dividing a non-zero number by 0 gives Infinity or -Infinity; only 0 / 0 is NaN.

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