Q. What will be the output of the following code snippet?
Code:var a = Math.max(); var b = Math.min(); print(a); print(b);
β
Correct Answer: (A)
-Infinity Infinity
Explanation:
Let's go through this carefully.
You have this JavaScript code:
var a = Math.max();
var b = Math.min();
print(a);
print(b);
Now:
- Math.max() with no arguments returns -Infinity.
- Math.min() with no arguments returns Infinity.
Why?
Because:
- Math.max() needs numbers to find the maximum. With no numbers, it returns the lowest possible value (-Infinity).
- Math.min() needs numbers to find the minimum. With no numbers, it returns the highest possible value (Infinity).
Thus:
- a = -Infinity
- b = Infinity
So, the output will be:
-Infinity
Infinity
Therefore, the correct answer is:
(A) -Infinity Infinity