+ 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 ?
4 Réponses
+ 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
+ 3
Bob ok that means we see firstly Math.min() method instead of Math.abs()
+ 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.
+ 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?