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
💬 Discuss
✅ Correct Answer: (C) Displays “Infinity”
Explanation:

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.

Explanation by: Official MCQ Buddy

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.

💬 Discussion


📊 Question Analytics

👁️
256
Total Visits
📽️
4 y ago
Published
🎖️
Babita
Publisher
📈
96%
Success Rate