A

Admin • 828.03K Points
Coach

Q. JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.

  • (A) Prints the value as such
  • (B) Prints an exception error
  • (C) Prints an overflow error
  • (D) Displays “Infinity”
  • Correct Answer - Option(D)
  • Views: 5
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

In JavaScript, when an arithmetic computation results in an indefinite or infinite value, JavaScript does not throw an error. Instead, it returns Infinity (or -Infinity for negative values).

Example:

console.log(10 / 0);  // Output: Infinity
console.log(-10 / 0); // Output: -Infinity

If the result of a computation is undefined (like 0/0), JavaScript returns NaN (Not-a-Number):

console.log(0 / 0); // Output: NaN

Why Not Other Options?

  • (A) Prints the value as such → ❌ Incorrect (JavaScript does not print raw values; instead, it handles them specifically as Infinity).
  • (B) Prints an exception error → ❌ Incorrect (JavaScript does not throw an exception for division by zero).
  • (C) Prints an overflow error → ❌ Incorrect (JavaScript does not have an "overflow error" like some other languages).

Final Answer:

(D) Displays “Infinity”

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.