Files
30-seconds-of-code/snippets/randomBoolean.md
2022-12-04 22:20:49 +02:00

415 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Random boolean value math,random chalarangelo blog_images/malibu.jpg 2021-01-20T16:20:08+02:00 2021-01-20T16:20:08+02:00

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