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”
πŸ’¬ Discuss
βœ… Correct Answer: (D) Displays β€œInfinity”
Explanation:

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”

Explanation by: Mr. Dubey

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”

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
341
Total Visits
πŸ“½οΈ
5 y ago
Published
πŸŽ–οΈ
Kirti
Publisher
πŸ“ˆ
90%
Success Rate