Javascript Reference - JavaScript sin() Method








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

Browser Support

sin() Yes Yes Yes Yes Yes

Syntax

Math.sin(x);

Parameter Values

Parameter Description
x Required. A number




Return Value

This method returns a value between -1 and 1, which represents the sine of the parameter x.

It returns NaN if the value is empty.

Example

The following code shows how to calculate the sine of a number.

<!--   w w w  . ja  v a  2s.  co  m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
  function doMath() {
    var inputNum1 = document.form1.input1.value;
    var result = Math.sin(inputNum1);
    document.form1.answer.value = result;
  }
</script>
</head>
<body>
  <form name=form1>
    Enter Number: <input type="text" name="input1" size=10> <input
      type="button" value="Calculate" onClick='doMath()'> <br>
    The sine is: <input type="text" name="answer" size=20>
  </form>
</body>
</html>

Click to view the demo