QWhat does JavaScript output when an infinite or definite value is encountered during an arithmetic computation in a programme?
Question Info
Choose the Best Option
Click any option to instantly check if you're correct.
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.