JavaScript Math.sin() Method

MD Niaz Rahman Khan Jan 30, 2023
  1. Syntax of Math.sin()
  2. Example 1: Use the Math.sin() Method in JavaScript
  3. Example 2: Use the Math.sin() Method With Non-Numeric Values
JavaScript Math.sin() Method

The Math.sin() method returns a numeric value that represents the sine of a number in radians. The return value is between -1 to 1.

Syntax of Math.sin()

Math.sin(num)

Parameters

num - The parameter num refers to a numeric value representing an angle in radians.

Return

The Math.sin() method returns the sine of a number in radians from a value between -1 to 1. This method will return NaN if something is passed that is Not a Number.

Example 1: Use the Math.sin() Method in JavaScript

const result1 = Math.sin(-1)
const result2 = Math.sin(0)
const result3 = Math.sin(1)

console.log(result1)
console.log(result2)
console.log(result3)

Output:

-0.8414709848078965
0
0.8414709848078965

We took three different numbers, -1, 0, and 1, and passed them as the parameter of the Math.sin() method. This method returned the sine of these numbers in radians.

Example 2: Use the Math.sin() Method With Non-Numeric Values

const result1 = Math.sin('A')
const result2 = Math.sin(Infinity)

console.log(result1)
console.log(result2)

Output:

NaN
NaN

This method returns NaN for both cases. The reason is the parameters are not a number.

MD Niaz Rahman Khan avatar MD Niaz Rahman Khan avatar

Niaz is a professional full-stack developer as well as a thinker, problem-solver, and writer. He loves to share his experience with his writings.

LinkedIn

Related Article - JavaScript Math