Math sin() Method - Javascript Math

Javascript examples for Math:sin

Description

The sin() method returns the sine of a number.

Parameter Values

Parameter Description
x Required. A number

Return Value:

A Number, from -1 to 1, representing the sine of an angle, or NaN if the value is empty

The following code shows how to return the sine of a number:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w  w  w  .  j av  a2  s.c o  m*/
    var a = Math.sin(3);
    var b = Math.sin(-3);
    var c = Math.sin(0);
    var d = Math.sin(Math.PI);
    var e = Math.sin(Math.PI / 2);

    var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials