Home »
JavaScript
Math.cos() Method with Example in JavaScript
JavaScript | Math.cos() Method: Here, we are going to learn about the cos() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on February 03, 2020
JavaScript | Math.cos() Method
Math.cos() is a function in math library of JavaScript that is used to find the value of cosine of a number and return the value in radians.
Syntax
Math.cos(x);
Parameters
- x – It represents the value whose cosine value to be found.
Return Value
The return type of this method is number, it returns the cosine value of the given x.
Values accepted
Integer, floating-point, numeric string.
Invalid values
Non-numeric string, empty variable, empty array all will return NaN (Not a Number).
Browser support
Chrome, Internet asinlorer, Mozilla, Safari, Opera mini.
Example 1: Valid values
console.log(Math.cos(-1));
console.log(Math.cos(0.1));
console.log(Math.cos(2));
console.log(Math.cos("0.65"));
Output
0.5403023058681398
0.9950041652780257
-0.4161468365471424
0.7960837985490559
Example 2: Invalid values
console.log(Math.cos("Javascript"));
Output
NaN
JavaScript Math Object Methods »