0% found this document useful (0 votes)
14 views3 pages

28 Math Object

The document discusses the JavaScript Math object which allows performing mathematical tasks. It includes constants like PI, methods like random() and round(), and provides examples of using various Math object properties and methods to generate random numbers between ranges or round numbers. The complete Math object reference is also mentioned.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

28 Math Object

The document discusses the JavaScript Math object which allows performing mathematical tasks. It includes constants like PI, methods like random() and round(), and provides examples of using various Math object properties and methods to generate random numbers between ranges or round numbers. The complete Math object reference is also mentioned.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Math Object

The Math object allows you to perform mathematical tasks.


Try it Yourself - Examples
rou!"#
$ow to use rou!"#.
ra!om"#
$ow to use ra!om"# to retur a ra!om umber betwee % a! &.
max"#
$ow to use max"# to retur the umber with the hi'hest value of two specifie! umbers.
mi"#
$ow to use mi"# to retur the umber with the lowest value of two specifie! umbers.
(omplete Math Object )eferece
*or a complete referece of all the properties a! metho!s that ca be use! with the Math
object+ 'o to our complete Math object referece.
The referece cotais a brief !escriptio a! examples of use for each property a! metho!,
Math Object
The Math object allows you to perform mathematical tasks.
The Math object iclu!es several mathematical costats a! metho!s.
Syntax for using properties/methods of Math:
var pi_value=Math.PI;
var sqrt_value=Math.sqrt(16);
Note: Math is ot a costructor. -ll properties a! metho!s of Math ca be calle! by usi'
Math as a object without creati' it.
Mathematical (ostats
JavaScript provi!es ei'ht mathematical costats that ca be accesse! from the Math object.
These are. E+ /0+ s1uare root of 2+ s1uare root of &32+ atural lo' of 2+ atural lo' of &%+ base-2
lo' of E+ a! base-&% lo' of E.
You may referece these costats from your JavaScript like this.
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.L2
Math.L1!
Math.L"#2E
Math.L"#1!E
Mathematical Metho!s
0 a!!itio to the mathematical costats that ca be accesse! from the Math object there are
also several metho!s available.
The followi' example uses the rou!"# metho! of the Math object to rou! a umber to the
earest ite'er.
$%&u'e(t.)rite(Math.r%u($(*.+));
The co!e above will result i the followi' output.
,
The followi' example uses the ra!om"# metho! of the Math object to retur a ra!om
umber betwee % a! &.
$%&u'e(t.)rite(Math.ra($%'());
The co!e above ca result i the followi' output.
!.!-.*+6.2+2!+./+,1
The followi' example uses the floor"# a! ra!om"# metho!s of the Math object to retur a
ra!om umber betwee % a! &%.
$%&u'e(t.)rite(Math.0l%%r(Math.ra($%'()111));
The co!e above ca result i the followi' output.
*

You might also like