- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Math.random
JavaScript Numbers & Math
JavaScript Math.random
Math.randomgives a random decimal between 0 and 1.
It includes 0 but never reaches 1.
Everything else is built by scaling that range.
Example
Example
javascript
const value = Math.random();
console.log(value >= 0 && value < 1);The output is true.
The value itself is different every time, so the check is what matters.
Building a Range
Multiply to widen the range.
Math.floor turns it into a whole number.
