Math.random() function in javascript

What is Math?

Before we learn about Math.random() function I would like to tell you that Math is an object in javascript.
The Math object includes several mathematical constants and methods.
Math object allows you to perform mathematical tasks.
Math is not a constructor, hence all properties and methods can be called by using Math as an object without creating it.


var a = Math.PI; //3.141592653589793
var b = Math.sqrt(25); //5


The random() method returns a random number from 0 to 1, but not 1.
It is defined in Math object.


var a = Math.random();
// here the value of a can be anything between 0 and 1 for example 0.6324468343159858

Click on below topics for step by step understanding.
How to get random element from Javascript Array and Display it.
Define an array in javascript
array.length in javascript
Math.floor() function in javascript



Comments are closed.