+ 3

Please explain, I am confused?

What is the value of the following expression? Math.abs(Math.min(-6,3)); Options:- 6 -6 3 Correct answer is: 6 My question is why the option not 3? Because if we see firstly absolute value then -6 is convert to 6 and 3 as it's 3, now if we see minimum value then why not 3 ?

21st Mar 2023, 12:11 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
4 Respuestas
+ 3
Math.abs(expression) returns the abs of a value, but here you've passed it a function. This needs to be evaluated to a value first so look at Math.min(-6,3). -6 <3 so it returns -6. Now our line of code is Math.abs(-6) which will return 6
21st Mar 2023, 12:17 PM
Bob
+ 3
Bob ok that means we see firstly Math.min() method instead of Math.abs()
21st Mar 2023, 12:18 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 3
Bob Thank you, I had a doubt mainly in this we solve Math.min() or we solve Math.abs() or you solve my doubt, thanks again.
21st Mar 2023, 2:06 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Yes. Math.abs knows how to do one thing. Return the absolute value of a number. If it sees something other than a number in the parenthesis, it evaluatesthat expression first. If it didn't you would get an error because what is the abs of a function?
21st Mar 2023, 12:44 PM
Bob