Booleans and comparisons · 부울린값과 비교
True and false
- A boolean is one of just two values:
trueorfalse. - Compare values to get a boolean:
===(equal),!==(not equal),<><=>=.
console.log(5 === 5); // → true
console.log(3 > 7); // → false
Combine tests
&&means and — true only when both sides are true.||means or — true when at least one side is true.!means not — it flipstrueandfalse.
console.log(true && false); // → false
console.log(!true); // → false
Truth table — try every input · 진리표 — 모든 입력을 시도해 보세요
&& (and) is true only when both are true. || (or) is true when at least one is. · &&(AND)은 두 값이 모두 참일 때만 참입니다. ||(OR)은 최소 하나가 참일 때 참입니다.
Watch out
- Always compare with
===, not==. The older==quietly converts types:0 == ""istrue! ===checks value and type, which is what you almost always want.
Common mistakes
- Prefer
===(strict) over==, which does surprising type coercion. &&is AND,||is OR,!is NOT.
Now you try
- Each task logs
trueorfalse. - Press Check answer to test it.
Use === to log whether 10 equals 10 (it is true). · ===을 사용하여 10이 10과 같은지 확인하고 로그로 출력하십시오 (그 결과는 true입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Log whether 8 is greater than 3 (it is true). · 8이 3보다 큰지 출력합니다(그 결과는 true입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
let n = 8. Log whether n is even by testing n % 2 === 0 (it is true). · let n = 8. n이 짝수인지 n % 2 === 0을 테스트하여 출력합니다(그 결과는 true입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
let age = 15. Use && to log whether the age is from 13 to 19 (a teenager) — it is true. · let age = 15. &&을 사용하여 나이가 13에서 19 사이(청소년)인지 출력합니다 — 그 결과는 true입니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.