The sin() method computes the trigonometric sine of the specified angle and returns it.
Example
sin() Syntax
The syntax of the Math.sin() method is:
Math.sin(angle)
Here, sin() is a static method. Hence, we are accessing the method using the class name, Math.
sin() Parameter
The sin() method takes a single parameter:
angle- in radians whose sine value is to be calculated
sin() Return Value
The sin() method returns:
- sine value of a given
angle(in radians) - NaN (Not a Number) for a non-numeric argument
Example 1: JavaScript Math.sin()
In the above example,
Math.sin(5)- computes the sine value of the angle 5Math.sin(-2)- computes the sine value of the angle -2
Example 2: Math.sin() with Math Constants
In the above example, we have used the sin() method to compute the sine of the math constant PI.
Here, the output -1.2246467991473532e-16 represents -1.2246467991473532 * 10-16
Example 3: Math.sin() with Non-Numeric Arguments
In the above example, we have tried to calculate the sine value of the string "David". Hence, we get NaN as the output.
Example 4: Math.sin() with Infinity argument
The sin() method doesn't treat infinity as a number so the method returns NaN with this argument.
Also, the sine of an infinite angle is indefinite, which can't be defined with a number.
Recommended readings: