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

πŸ‘οΈ
270
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Babita
Publisher
πŸ“ˆ
81%
Success Rate