What is Math in JavaScript? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript provides a built-in Math object that provides a set of methods to perform mathematical operations. These operations range from basic to more complex functions like trigonometry and logarithms. The Math object allows you to perform calculations without the need for writing custom functions. Syntax:Math.methodName(argument1, argument2, ...);The Math object in JavaScript provides a variety of methods to perform various mathematical operations, some of the Math object methods are listed below: Math.sin(x): It returns the sine of x (in radians).Math.cos(x): It returns the cosine of x (in radians).Math.tan(x): It returns the tangent of x (in radians).Math.pow(x, y): It returns the value of x raised to the power of y.Math.sqrt(x): It returns the square root of x.Math.log(x): It returns the natural logarithm of x.Math.exp(x): It returns e raised to the power of x.Math.random(): It returns a pseudo-random number between 0 (inclusive) and 1 (exclusive).Example 1: This example is demonstrating using of Math object methods to perform trigonometry, exponents, and logarithms operations. JavaScript let x = 10; // Trigonometry let angleInRadians = Math.PI / 4; // 45 degrees let sineValue = Math.sin(angleInRadians); let cosineValue = Math.cos(angleInRadians); let tangentValue = Math.tan(angleInRadians); console.log("Sine:", sineValue); console.log("Cosine:", cosineValue); console.log("Tangent:", tangentValue); // Exponents and Logarithms let base = 2; let exponent = 3; let powerResult = Math.pow(base, exponent); let squareRootResult = Math.sqrt(x); let logarithmResult = Math.log(x); let exponentialResult = Math.exp(x); console.log("Power:", powerResult); console.log("Square Root:", squareRootResult); console.log("Natural Logarithm:", logarithmResult); console.log("Exponential:", exponentialResult); OutputSine: 0.7071067811865475 Cosine: 0.7071067811865476 Tangent: 0.9999999999999999 Power: 8 Square Root: 3.1622776601683795 Natural Logarithm: 2.302585092994046 Exponential: 22026.465794806718 Example 2: This example is demonstrating using of Math object method Math.random() to generate random number between 1 to 100. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <title> Random Number Generator </title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } </style> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h2> Random Number Generator </h2> <p> Click the button to generate a random number between 1 to 100: </p> <button onclick="generateRandomNumber()"> Generate Random Number </button> <p id="randomNumber"></p> <script> const generateRandomNumber = () => { let randomNumber = Math.floor(Math.random() * 100) + 1; document.getElementById("randomNumber"). innerText = `Random Number: ${randomNumber}`; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article What is the use of Math object in JavaScript ? J jaimin78 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Geeks Premier League 2023 Similar Reads What is JavaScript? JavaScript is a powerful and flexible programming language for the web that is widely used to make websites interactive and dynamic. JavaScript can also able to change or update HTML and CSS dynamically. JavaScript can also run on servers using tools like Node.js, allowing developers to build entire 6 min read What is the use of Math object in JavaScript ? The Math object in JavaScript provides a set of methods and properties for mathematical constants and functions. It is a built-in object that allows for performing mathematical operations and accessing mathematical constants without creating an instance.What is the Math Object?The Math object is an 4 min read JavaScript Course What is JavaScript ? JavaScript is a very famous programming language that was originally started in the year of 1995 with the motive of making web pages alive. It is also an essential part of the web developer skillset. In simple terms, if you want to learn web development then learn HTML & CSS before starting JavaScri 3 min read What are the Gotchas in JavaScript ? Javascript truly is a popular language due to its simplicity and versatility. Despite having many merits, Javascript is a funny language that can confuse you at times especially for those accustomed to the traditional OOP language. The tricky parts or 'gotchas' (not limited to the following) are: == 3 min read JavaScript Math E Property The Math.E is a property in JavaScript that simply returns the value of Euler's Number, which is nothing but just has a base of the natural logarithm. Its value is approximately around of 2.71828.Syntax:Math.E;Math.E â 2.718Return Values:It simply returns the value of the base of the natural logarit 2 min read Getting Started with JavaScript JavaScript is a lightweight, single-threaded, dynamically typed, interpreted programming language with object-oriented capabilities. Primarily JavaScript is used to add interactivity and dynamism to web pages. It breathes life into static HTML and CSS, enabling features like dynamic content updates, 8 min read Like