DONATE  
MENU
HTML
AJAX
JSON
JAVASCRIPT

JavaScript Tutorials

INTRODUCTION

» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls

CONDITIONAL TESTING

» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement

LOOPS

» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop

FUNCTIONS

» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions

ARRAYS

» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays

OBJECTS

» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword

AJAX

» Introduction to AJAX

JSON

» Introduction to JSON

JAVASCRIPT DATES

» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)

MATH OBJECT

» Math Object

» Math Methods

HTML / JS DOM

» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events

MISCELLANEOUS

» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript

JAVASCRIPT EXAMPLES

» JavaScript Calculator

.. » JavaScript » Math Object » Math Object
Share Tweet WhatsApp

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>

Copy PRACTICE IT

You can easily make use of a method of the Math object.
<script>
alert(Math.pow(3,2));
</script>

Copy PRACTICE IT

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>

Copy PRACTICE IT

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>

Copy PRACTICE IT

3. LN2 It returns the natural logarithm of 2.
<script>
document.write(Math.LN2);
</script>

Copy PRACTICE IT

4. LN10 Just like the LN2, it returns the natural logarithm of 10.
<script>
document.write(Math.LN10);
</script>

Copy PRACTICE IT

5. LOG2E Returns the base 2 logarithm of E.
<script>
document.write(Math.LOG2E);
</script>

Copy PRACTICE IT

6. LOG10E Returns the base 10 logarithm of E.
<script>
document.write(Math.LOG10E);
</script>

Copy PRACTICE IT

7. SQRT2 It's value is the square root of 2.
<script>
document.write(Math.SQRT2);
</script>

Copy PRACTICE IT

8. SQRT1_2 Returns the square root of 1/2 or half.
<script>
document.write(Math.SQRT1_2);
</script>

Copy PRACTICE IT

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