The Math.con() function in Javascript is used to return the cosine of a number.
The Math.cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle given in radians.
cos() is a static method of Math, therefore, it is always used as Math.cos(), rather than as a method of a Math object created.
Syntax:
Math.cos(value)
Parameters Used:
Value:A number given in radians.
Return Value:
The Math.cos() function returns the cosine of the given numbers which range from -1 to 1.
Examples:
- When zero is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cos(0));
</
script
>
Output:
Output : 1
- When 1 is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cos(1));
</
script
>
Output:
Output : 0.5403023058681398
- When PI is passed as a parameter.
<
script
type
=
"text/javascript"
>
document.write("Output : " + Math.cos(Math.PI));
</
script
>
Output:
Output : -1
leave a comment
0 Comments