Using Math cos() function to coding in Javascript/JS

This JavaScript tutorial explains how to use the math function referred to as cos() with syntax and examples.


In JavaScript, cos() is a characteristic that is used to return the cosine of a number. Because the cos() function is a static function of the Math object, it need to be invoked thru the placeholder object referred to as Math.


In JavaScript, the syntax for the cos() characteristic is:


Parameters or Arguments

number The variety used to calculate the cosine. It is the price of an attitude expressed in radians.


The cos() function returns the cosine of a number. The result will be a price between 1 and -1.


To convert levels to radians, multiply via 2π/360 or 0.017453293. Math is a placeholder object that carries mathematical functions and constants of which cos() is one of these functions.


Let’s take a look at an instance of how to use the cos() function in JavaScript.

For example:


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

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

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


In this example, the first output to the console log again 0.7316888688738209 which is the cosine of 0.75.

The second output to the console log lower back 0.6216099682706644 which is the cosine of -0.9.

The 0.33 output to the console log again -0.4161468365471424 which is the cosine of two