๐Ÿ“Š JavaScript
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

๐Ÿ‘๏ธ
244
Total Visits
๐Ÿ“ฝ๏ธ
4 y ago
Published
๐ŸŽ–๏ธ
Kirti
Publisher
๐Ÿ“ˆ
96%
Success Rate