5 falsy values: 0, '', undefined, null, NaN
console.log(Boolean(0));
// prints false
console.log(Boolean(undefined));
// prints false
console.log(Boolean('Jonas'));
// prints true
console.log(Boolean({}));
// prints true
console.log(Boolean(''));
// prints false
0은 Falsy Value이기 때문에-
else 문이 실행됨
const money = 0;
if (money) {
console.log("Don't spend it all");
} else {
console.log("나가서 돈을 벌어오쟈");
}
// prints 나가서 돈을 벌어오쟈
undefined는 falsy value이기 때문에 else문이 실행됨
let height;
if (height) {
console.log('YAY! Height is defined');
} else {
console.log('Height is UNDEFINED')
}
// prints Height is UNDEFINED
'Programming > JavaScript' 카테고리의 다른 글
Coding Challenge #3 - Compare the team's average scores using if / else statements (0) | 2022.08.25 |
---|---|
The switch Statement (0) | 2022.08.25 |
Type Conversion and Coercion (0) | 2022.08.21 |
Coding Challenge #2 - BMI Comparison using if / else statements (0) | 2022.08.21 |
Taking Decisions: if / else Statements (0) | 2022.08.16 |