Q. What will be the output of the following code snippet?

Code:
var a = Math.max();
var b = Math.min();
print(a);
print(b);
  • (A) -Infinity Infinity
  • (B) Infinity -Infinity
  • (C) Infinity Infinity
  • (D) -Infinity -Infinity
πŸ’¬ Discuss
βœ… 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

Explanation by: Mr. Dubey

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
219
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
87%
Success Rate