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 −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .sample {
      font-size: 18px;
      font-weight: 500;
      color: red;
<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>
Click on the above button to see some math Object methods
   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>';


On clicking the “CLICK HERE” button −