- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Math Object example
The JavaScript Math object allows us to perform mathematical operation on numbers. It has properties and methods for mathematical constants and functions.
Following is the code to implement the JavaScript Math Object with some of its properties and methods −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; color: red; } </style> </head> <body> <h1>JavaScript Math Object</h1> <div class="sample"></div> <div style="font-weight: bold; color: black;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to see some math Object methods </h3> <script> let sampleEle = document.querySelector(".sample"); document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML = 'Math.round(7.7) = ' + Math.round(7.7) + '<br>'; sampleEle.innerHTML += 'Math.sqrt(121) = ' + Math.sqrt(121) + '<br>'; sampleEle.innerHTML += 'Math.pow(4,4) = ' + Math.pow(4,5) + '<br>'; }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- What is math object in JavaScript?
- What is Math Object in JavaScript Program?
- Math. fround() function in JavaScript
- Math. hypot() function in JavaScript
- What are JavaScript Math Functions?
- Get minimum number without a Math function JavaScript
- Explain Deep cloning an object in JavaScript with an example.
- Check for perfect square without using Math libraries - JavaScript
- Implementing Math function and return m^n in JavaScript
- How to create a JSON object in JavaScript? Explain with an example.
- JavaScript: How to Find Min/Max Values Without Math Functions?
- JavaScript Numbers example
- JavaScript Prompt Example
- Given an example of Luminous Object.
- Math Class in C#

Advertisements