This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer
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.
This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer | Sciencx (2021-04-09T13:24:14+00:00) JavaScript Interview Question #31: Big or small. Retrieved from https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
