A

Admin • 833K Points
Coach

Q. When there is an indefinite or an infinity value during an arithmetic value computation, javascript

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

Explanation by: Admin

In JavaScript, when an arithmetic operation results in an infinite value (e.g., division by zero or exceeding the largest representable number), JavaScript does not throw an error. Instead, it represents the result as Infinity or -Infinity, depending on the sign of the operation.

Examples:

console.log(1 / 0);    // Output: Infinity
console.log(-1 / 0); // Output: -Infinity
console.log(10 ** 1000); // Output: Infinity (Number too large)
console.log(-10 ** 1000); // Output: -Infinity

This behavior ensures that JavaScript handles extreme values gracefully without stopping the execution of the script.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.