JavaScript Math sin() method

The sin function in JavaScript computes the sine of a specified number. The output generated by the sin function lies within the interval of -1 to 1, corresponding to the sine value of the angle.

Syntax

The sin function can be denoted using the syntax outlined below:

Example

Math.sin(num)

Parameter

num - A number.

Return

The sine of the number.

JavaScript Math sin method example

In this section, we will explore the sin function by examining a series of examples.

Example 1

Let's see a simple example of sin method.

Example

<script>

document.writeln(Math.sin(1)+"<br>");

document.writeln(Math.sin(2));

</script>

Output:

Output

0.8414709848078965

0.9092974268256817

Example 2

In this illustration, we will demonstrate the use of the sin function with negative values.

Example

<script>

document.writeln(Math.sin(-1)+"<br>");

document.writeln(Math.sin(-0.5));

</script>

Output:

Output

-0.8414709848078965

-0.479425538604203

Example 3

Let us examine the sin function using a variety of test scenarios.

Example

<script>

document.writeln(Math.sin(0)+"<br>");

document.writeln(Math.sin(Math.PI));

</script>

Output:

Output

0

1.2246467991473532e-16

Example 4

In this section, you have the opportunity to evaluate the sin function using your own custom test cases.

Example

<script>

function display()

{

  var x=document.getElementById("num").value;

document.getElementById("result").innerHTML=Math.sin(x);

}

</script>

<form>

  Enter a number: <input type="text" id="num">

  <input type="button"  onclick="display()" value="submit">

  </form>

  <p><span id="result"></span></p>

Input Required

This code uses input(). Please provide values below: