totn JavaScript

JavaScript: Math sin() function

This JavaScript tutorial explains how to use the math function called sin() with syntax and examples.

Description

In JavaScript, sin() is a function that is used to return the sine of a number. Because the sin() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the sin() function is:

Math.sin(number);

Parameters or Arguments

number
The number used to calculate the sine. It is the value of an angle expressed in radians.

Returns

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

Note

  • To convert degrees to radians, multiply by 2π/360 or 0.017453293.
  • Math is a placeholder object that contains mathematical functions and constants of which sin() is one of these functions.

Example

Let's take a look at an example of how to use the sin() function in JavaScript.

For example:

console.log(Math.sin(2));
console.log(Math.sin(0));
console.log(Math.sin(-0.9));

In this example, we have invoked the sin() function using the Math class.

We have written the output of the sin() function to the web browser console log, for demonstration purposes, to show what the sin() function returns.

The following will be output to the web browser console log:

0.9092974268256817
0
-0.7833269096274834

In this example, the first output to the console log returned 0.9092974268256817 which is the sine of 2.

The second output to the console log returned 0 which is the sine of 0.

The third output to the console log returned -0.7833269096274834 which is the sine of -0.9.