DEV Community

Cover image for JavaScript Interview Question #31: Big or small
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Originally published at learn.coderslang.com on

JavaScript Interview Question #31: Big or small

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.

Learn Full-Stack JavaScript

Top comments (1)

Collapse
 
raddevus profile image
raddevus

Yeah, I recently wrote up a very short article here on Dev.to about this (Esoteric Questions During Front-end Interview: Valid?) Questions you should ask your interviewer if they ask you an esoteric tech question.