Adding another way to check falsey boolean values (#21129)
Checking using !! to get the boolean value may be easier than setting up a conditional. Also linking to the truthy freeCodeCamp guide.
This commit is contained in:
@ -4,7 +4,7 @@ title: Falsy Values
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
A falsy value is something which evaluates to FALSE, for instance when checking a variable. There are only six falsy values in JavaScript: `undefined`, `null`, `NaN`, `0`, `""` or `''` (empty string), and `false` of course.
|
A falsy value is something which evaluates to FALSE, for instance when checking a variable. There are only six falsy values in JavaScript: `undefined`, `null`, `NaN`, `0`, `""` or `''` (empty string), and the Boolean `false` of course. All other values are [truthy](https://github.com/freeCodeCamp/freeCodeCamp/edit/master/guide/english/javascript/truthy-values/index.md).
|
||||||
|
|
||||||
## Checking for falsy values on variables
|
## Checking for falsy values on variables
|
||||||
|
|
||||||
@ -16,6 +16,11 @@ if (!variable) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also get the boolean value of a variable by using the bang operator (`!`) twice:
|
||||||
|
```javascript
|
||||||
|
!!variable // When the variable is falsy, a double bang (!!) will evaluate to the Boolean false.
|
||||||
|
```
|
||||||
|
|
||||||
## General Examples
|
## General Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
Reference in New Issue
Block a user