MENU

# Math Object

The JavaScript Math Object contains properties and methods that enables you to quickly carry out mathematical operations. For example, instead of defining a function to raise a number to a certain power,
``````<script>
function raiseTo(num, raiseTo){
var answer = 1;
for (var i = 1; i<=raiseTo; i++){
answer *= num;
}
return answer;
}

alert(raiseTo(3,2));
</script>``````
You can easily make use of a method of the Math object.
``````<script>
alert(Math.pow(3,2));
</script>``````
In this page, you shall get familiarized with some of the properties and methods of the Math Object. To start using the properties and methods of the Math object, you don't need to create an object of the Math prototype on a variable. This is because Math is not a prototype but rather a literal object created from the Object() prototype. Math Properties Below are some of the properties and methods of the Math object. Their names are capitalized because they are constants whose values cannot be change. 1. E The E property of the Math object basically returns the Euler's number.
``````<script>
document.write(Math.E);
</script>``````
2. PI The PI property returns the mathematical PI which is equivalent to 22/7 usually used in working with circles.
``````<script>
document.write(Math.PI);
</script>``````
3. LN2 It returns the natural logarithm of 2.
``````<script>
document.write(Math.LN2);
</script>``````
4. LN10 Just like the LN2, it returns the natural logarithm of 10.
``````<script>
document.write(Math.LN10);
</script>``````
5. LOG2E Returns the base 2 logarithm of E.
``````<script>
document.write(Math.LOG2E);
</script>``````
6. LOG10E Returns the base 10 logarithm of E.
``````<script>
document.write(Math.LOG10E);
</script>``````
7. SQRT2 It's value is the square root of 2.
``````<script>
document.write(Math.SQRT2);
</script>``````
8. SQRT1_2 Returns the square root of 1/2 or half.
``````<script>
document.write(Math.SQRT1_2);
</script>``````
You will learn the various Math methods in the next page. SUMMARY
1. The JavaScript Math object contains properties and methods that can help you to easily carry out mathematical operations in your programs.
2. In this page, we listed the various properties of the Math object.
3. They allow you to get certain numbers that are useful for mathematical operations. For example, the PI property whose value is the popular mathematical PI.
4. There are other numerous properties.
5. You should note that you don't need to create an object of the Math to start using its properties. It is already a literal object and not a prototype.
Take a short quiz on Math Object.
Ask a question or tell us if Math Object is easy or not.
cent?

Join our 1,090 subscribers to receive tutorials' updates!

We won't spam your mail box. We hate it.

StackBeginner 2021 © Joseph Omamode