Single Choice Not Set

QWhat does JavaScript output when an infinite or definite value is encountered during an arithmetic computation in a programme?

ID: #4832 Python Basic MCQ 203 views
Question Info
#4832Q ID
Not SetDifficulty
Python Basic MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Prints an exception error
  • B Prints an overflow error
  • C Displays "Infinity"
  • D Prints the value as such
Correct Answer

Explanation

In JavaScript, if the result of an arithmetic operation is larger than the largest representable number,
the result will be positive infinity.
Similarly, if the result of an arithmetic operation is smaller than the smallest representable negative number,
the result will be negative infinity.
For example, consider the following code:

let x = 1.7976931348623157e+308;
let y = x * 2;
console.log(y); // prints "Infinity"

let a = -1.7976931348623157e+308;
let b = a * 2;
console.log(b); // prints "-Infinity"

In this example, the variables x and a are assigned the largest and smallest representable numbers, respectively.
When these numbers are multiplied by 2, the result is positive and negative infinity, respectively.

Share This Question

Challenge a friend or share with your study group.