What is the use of the Math.random() function in JavaScript ?
The Math.random()
function is used to generate a pseudo-random floating-point number between 0 (inclusive) and 1 (exclusive).
Syntax:
Math.random();
Example: Here, Math.random()
generates a random number, which could be any floating-point value between 0 (inclusive) and 1 (exclusive). This random number is then stored in the variable randomNumber
, and its value is printed to the console.
Javascript
let randomNumber = Math.random(); console.log(randomNumber); |
Output
0.09157103247687903
Contact Us