mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
3 years ago | |
---|---|---|
.. | ||
README.md | 3 years ago |
README.md
Seeker of Truth
Truthy and Falsy
In JS, all values are either truthy or falsy, this means if used in a condition, truthy values will validate the condition while falsy values would not.
Here is the list of falsy values:
undefined
andnull
- the numbers
0
andNaN
- the empty string
''
- and the boolean
false
of course
All other values are truthy, note that empty arrays and empty objects are truthy, but the empty string is not.
if ('') {
console.log('Since empty string are falsy, this will never log')
}
if ('hello') {
console.log('this will always log as the string is not empty')
}
Operator !
The !
(NOT operator) can be used to convert a truthy value to false
or a falsy value to true
.
example:
let money = 0
let noMoney = !money
console.log(noMoney) // true
In this case, 0 is falsy, so the !
return the value true
Instructions
R
let truth = 0
if (!truth) {
console.log()
}