JavaScript Interview Question #31: Big or small

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 su…


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer

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


This content originally appeared on DEV Community and was authored by Coderslang: Become a Software Engineer


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » JavaScript Interview Question #31: Big or small." Coderslang: Become a Software Engineer | Sciencx - Friday April 9, 2021, https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/
HARVARD
Coderslang: Become a Software Engineer | Sciencx Friday April 9, 2021 » JavaScript Interview Question #31: Big or small., viewed ,<https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/>
VANCOUVER
Coderslang: Become a Software Engineer | Sciencx - » JavaScript Interview Question #31: Big or small. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/
CHICAGO
" » JavaScript Interview Question #31: Big or small." Coderslang: Become a Software Engineer | Sciencx - Accessed . https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/
IEEE
" » JavaScript Interview Question #31: Big or small." Coderslang: Become a Software Engineer | Sciencx [Online]. Available: https://www.scien.cx/2021/04/09/javascript-interview-question-31-big-or-small/. [Accessed: ]
rf:citation
» JavaScript Interview Question #31: Big or small | Coderslang: Become a Software Engineer | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.