JavaScript Math.sin()
Syntax & Examples


Math.sin() static-method

The Math.sin() static method in JavaScript returns the sine of a number. The number is assumed to be in radians.


Syntax of Math.sin()

The syntax of Math.sin() static-method is:

Math.sin(x)

This sin() static-method of Math returns the sine of the given number x, where x is in radians.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number representing an angle in radians whose sine is to be calculated.

Return Type

Math.sin() returns value of type Number.



✐ Examples

1 Using Math.sin() with a positive angle

In JavaScript, we can use the Math.sin() method to calculate the sine of a positive angle given in radians.

For example,

  1. We pass the angle Math.PI / 2 radians (which is 90 degrees) to the Math.sin() method.
  2. The result, 1, indicates the sine of 90 degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.sin(Math.PI / 2);
console.log(result);

Output

1

2 Using Math.sin() with a negative angle

In JavaScript, we can use the Math.sin() method to calculate the sine of a negative angle given in radians.

For example,

  1. We pass the angle -Math.PI / 2 radians (which is -90 degrees) to the Math.sin() method.
  2. The result, -1, indicates the sine of -90 degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.sin(-Math.PI / 2);
console.log(result);

Output

-1

3 Using Math.sin() with zero

In JavaScript, we can use the Math.sin() method to calculate the sine of zero radians.

For example,

  1. We pass the angle 0 radians to the Math.sin() method.
  2. The result, 0, indicates the sine of zero degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.sin(0);
console.log(result);

Output

0

Summary

In this JavaScript tutorial, we learned about sin() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.