Datatype
boolean
Returns the boolean value true or false.
Note:
A probability of 0.75
results in true
being returned 75%
of the calls; likewise 0.3
=> 30%
.
If the probability is <= 0.0
, it will always return false
.
If the probability is >= 1.0
, it will always return true
.
The probability is limited to two decimal places.
Available since v5.5.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
options | number | { ... } | {} | The optional options object or the probability ( |
options.probability? | number | 0.5 | The probability ( |
Returns: boolean
ts
function boolean(
options:
| number
| {
probability?: number;
} = {}
): boolean;
Examples
ts
faker.datatype.boolean() // false
faker.datatype.boolean(0.9) // true
faker.datatype.boolean({ probability: 0.1 }) // false