For example, if you want to return the absolute value of the number, then you can use abs () method, like:
Var sharp = Math.abs();
SQRT2 – It will return the square root of 2. It will give you the approx value.
SQRT1_2 – it will return the square root of ½.
PI – It will return the value of pi (22/7).
LN2 – It will return the natural logarithm of 2.
LN10 – It will return the natural logarithm of 10.
LOG10E – It will show the base 10 logarithm of E.
Now let’s try to understand the use of properties with the simple to understand example. We are using ‘SQRT2’ property to understand the use of properties. As we know that ‘SQRT2’ will return the square root of the 2. Let’s see the output in the below code.
The output will be:
the value of sharp property is : 1.4142135623730951
In this section, we will list some of the frequently used methods by the developer.
abs () – The ‘abs’ is short for Absolute, and it will return the absolute value of a number.
acos () – Returns the arccosine in radians of the number.
asin () – We can use it to get arcsine in radians of the number.
atan () – We can use it to get the arctangent in radians of the number.
ceil () – We can use it to get the smallest integer (either greater than or equal to the number).
cos () – We can use it to get the cosine of the number in radians.
exp () – We cause use it to get the value of En, here E stands for ‘Euler’ and n stands for the ‘argument’.
floor ()- We can use it to get the largest integer (either greater than or equal to the number).
pow () – W can use it, to get the base exponent of the number.
random () – We can use it to get the random numbers between the 0 and 1.
sqrt() – We can use it to get the square root of a number.
tan() – We can use it to find the tangent of the number.
When you will run this program, then the output would be:
First perfect square : 7
It is not a perfect square : 6.992853494818835
We have called the sqrt() method by using the predefined object ‘ math’. Like the above example, you can try the methods. It is not at all hard to implement methods.
Tips to Remember
- You need not to create its object first, because it has no constructor.