InterviewSolution
Saved Bookmarks
| 1. |
Role of “use strict” in JavaScript |
|
Answer» The Math.ABS() method is used in JavaScript to FIND the absolute value of a number. The FOLLOWING is the parameter of abs(val) method:
The method returns:
Let us see an example to get the absolute value of a negative number: var val = -9.50;To get the absolute value: Math.abs(val);The entire example: <!DOCTYPE html> <html> <body> <script> var val = -9.50; document.write("Number: "+val); var res = Math.abs(val); document.write("<br>Absolute Value: "+res); </script> </body> </html>The output returns the negative value: Number: -9.5 Absolute Value: 9.5Let us see another example for “null” as input: <!DOCTYPE html> <html> <body> <script> var val = null; document.write("Number: "+val); var res = Math.abs(val); document.write("<br>Absolute Value: "+res); </script> </body> </html>The output: Number: null Absolute Value: 0Let us see another example to get the absolute value: <!DOCTYPE html> <html> <body> <script> var val = 15+30+55; document.write("Number: "+val); var res = Math.abs(val); document.write("<br>Absolute Value: "+res); </script> </body> </html>The output: Number: 100 Absolute Value: 100 |
|