Files
30-seconds-of-code/snippets/randomBoolean.md
2021-01-20 16:20:08 +02:00

290 B

title, tags
title tags
randomBoolean math,random,beginner

Generates a random boolean value.

  • Use Math.random() to generate a random number and check if it is greater than or equal to 0.5.
const randomBoolean = () => Math.random() >= 0.5;
randomBoolean(); // true