# JavaScript Math sin: The Complete Guide

0
13 The Math.sin() function in Javascript is used to return the sine of the number. For example, the sin() method returns the numeric value between -1 and 1, representing the sine of the angle given in radians. Javascript sin() is a static method of Math; therefore, it is always used as Math. The sin() is a static method of Math, and it can be used without creating an object.

## JavaScript Math sin()

The Math sin() is a built-in JavaScript function that finds the sine value of a given argument. The Math.sin() method comes in handy in programming contexts dealing with trigonometric expressions.

### Syntax

```Math.sin(x)
```

### Parameter(s)

The variable x (in radians) whose sine value is to be determined.

### Return Value

The sine value is between -1 and 1. #### Note

• If the passed value is empty, the sin() method returns NaN.

### Compatibility(Version and above)

2. Internet Explorer v3
3. Firefox v1
4. Edge v12
5. Opera v3
6. Safari v1
7. Android webview v1
8. Chrome for Android v18
9. Firefox for Android v4
10. Opera for Android v10.1
11. Safari on iOS v1
12. Samsung Internet v1.0
13. Node.js

JavaScript version: ECMAScript 1

Consider the following examples.

### JavaScript Math sin() function

The following code demonstrates the use of the sin() method.

```// app.js

let a = 0;
let b = 1;
let c = Math.PI;
let d = 2 * Math.PI;
let e = (Math.PI) / 2;

console.log(Math.sin(a));
console.log(Math.sin(b));
console.log(Math.sin(c));
console.log(Math.sin(d));
console.log(Math.sin(e));
```

#### Output

```node app
0
0.8414709848078965
1.2246467991473532e-16
-2.4492935982947064e-16
1```

### Example 2

The following example demonstrates the case where an empty value is passed.

```// app.js

let x;

console.log(Math.sin(x));
console.log(Math.sin());
```

#### Output

```node app
NaN
NaN
```

### Example 3

The following code example demonstrates an application of the Math.sin() method in the simple programming context.

Given the base angle of the triangle and the base side, find all the remaining sides of the triangle.

```// app.js

// Given the base angle of a triangle and the base side,
// find all the remaining sides of the triangle.

let p;
let b;
let h;

let angle;

const rl = r.createInterface({
input: process.stdin,
output: process.stdout
});

const prompt1 = () => {
return new Promise((resolve, reject) => {
rl.question('Base side: ', (answer) => {
resolve();
});
});
};

const prompt2 = () => {
return new Promise((resolve, reject) => {
resolve();
});
});
};

const main = async () => {
await prompt1();
await prompt2();
rl.close();

console.log('The three sides of the triangle are:');
console.log(b); //base side

let angle2 = (Math.PI) / 2 - angle;

h = b / (Math.sin(angle2));
console.log(h); //hypotenuse

p = h * Math.sin(angle);

console.log(p); //third side
}

main();
```

#### Output

```Test Case 1:
->node example3
Base side: 6
The three sides of the triangle are:
6
6.928204127882605
3.464103410351597

Test Case2:
->node example3
Base side: 30
The three sides of the triangle are:
30
42.42639993882793
29.99999019615471

```