JavaScript Math sin() Method
The JavaScript Math sin( ) method in Javascript is used to return the sine of a number. The Math.sin() method returns a numeric value between -1 and 1, which represents the sine of the angle given in radians. The sin() is a static method of Math, therefore, it is always used as Math.sin(), rather than as a method of a Math object created.
Syntax:
Math.sin(value)
Parameters:
This method accepts a single parameter as mentioned above and described below:
- value: Which is a number given in radians.
Return Value:
The Math.sin() method returns the sine of the given numbers between 1 and -1.
Example 1: Below is an example of the Math sin() Method.
console.log("When zero is passed as a parameter: "
+ Math.sin(0));
Output
When zero is passed as a parameter: 0
Example 2: When 1 is passed as a parameter.
console.log("Result : " + Math.sin(1));
Output
Result : 0.8414709848078965
Example 3: When PI is passed as a parameter.
console.log("Result : " + Math.sin(Math.PI / 2));
Output
Result : 1
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported Browsers
- Chrome 51
- Edge 15
- Firefox 54
- Safari 10
- Opera 38
JavaScript Math sin() Method – FAQs
What does the Math.sin() method do in JavaScript?
The Math.sin() method returns the sine of a number, where the number is given in radians.
Can Math.sin()
handle special numeric values like NaN
, Infinity
, and -Infinity
?
Math.sin(NaN)
returnsNaN
.Math.sin(Infinity)
andMath.sin(-Infinity)
returnNaN
.
What happens if the argument is not a number?
If the argument is not a number, Math.sin() converts it to a number. If the conversion is not possible, the result is NaN (Not-a-Number).
What is the range of values returned by Math.sin()?
The values returned by Math.sin() range from -1 to 1, inclusive.
What are common use cases for the Math.sin()
method?
- Trigonometric Calculations: Using
Math.sin()
in mathematical and physics calculations involving angles.- Waveform Generation: Generating sine waves for audio processing, signal processing, and simulations.
- Graphics and Animations: Calculating positions and movements in computer graphics and animations.
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.