js-test-31

What’s the output?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

So, there’s an if statement and it’s condition Math.max() > 0 is all we need to analyze.

If your first guess was that Math.max() should return some big number that’s for sure bigger than 0, then you’re wrong.

In JavaScript Math.max() takes a variable number of arguments and returns the biggest one. The comparison starts at the very bottom, which in JS is -Infinity because it’s smaller than all other numbers.

This is why if no arguments are provided to the Math.max(), it will return -Infinity.

As -Infinity is smaller than 0, we’ll go into the else branch of the conditional statement.


ANSWER: string ZERO! will be logged to the console.