JavaScript Tutorial

Define JavaScript

JavaScript Comment

JavaScript Variable

JavaScript Data Types

JS Popup Boxes

Type Conversions

JavaScript Functions

JavaScript Operators

Arithmetic Operator, Ex

Conditional Statements

Logical Operators

JavaScript Loops

Function Expressions

Arrow Function

JavaScript Arrays

JavaScript Events

JS Mouse Events

JS Keyboard Events

Styling Elements

JS String Functions

JS Math Functions

JS Random Function

JS Date Functions

JS Theme Change

JS Noscript Tag

JavaScript Objects

JavaScript Constructor

JavaScript Class

JS Assignment

JS Question-Answer

Page Stats

Visitor: 688

JavaScript Math Functions

JavaScript Math functions allows you to perform some mathematical tasks. Common JavaScript Mathematical functions are:

S.No.MethodsDescription
Math.min()
Math.min(0, 150, 30, 20, -8)
Returns the Smallest number
Returns -8
Math.max()
Math.max(0, 150, 30, 20, -8)
Returns the Largest number
Returns 150
Math.random()Returns a Random number between 0 and 1
Math.round()
Math.round(4.7)
Math.round(4.4)
Returns a number to the nearest integer.
Returns 5
Returns 4
Math.ceil()
Math.ceil(4.4)
Rounds a number up to the nearest integer.
Returns 5
Math.floor()
Math.floor(4.7)
Rounds a number down to the nearest integer
Returns 4
toFixed()
var x = 9.656;
x.toFixed(0);
x.toFixed(2);
x.toFixed(4);
Fix the decimal places.

returns 10
returns 9.66
returns 9.6560
toPrecision()
var x = 9.656;
x.toPrecision();
x.toPrecision(2);
x.toPrecision(4);
x.toPrecision(6);
Returns the total number of digits

returns 9.656
returns 9.7
returns 9.656
returns 9.65600
Math.floor(Math.random() * 11) Returns a random number between 0 and 10
Math.pow(x,y)Returns the value of x to the power of y
Math.sqrt(x)Returns the square root of x

NaN - Not a Number
NaN is a JavaScript reserved word indicating that a value is not a number.
var x = "Apple";
isNaN(x); // returns true because x is Not a Number

Conversion Method
parseInt() - Parses its argument and returns an integer
parseFloat() - Parses its argument and returns a floating point number.