W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더). - Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외) - Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체) - Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속) 각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7.5 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| javascript-booleans | JavaScript Booleans | Frontend | draft | conceptual |
|
B | 0.89 | 2026-06-23 | 2026-06-23 |
|
|
JavaScript Booleans
🎯 한 줄 통찰 (One-line insight)
A Boolean is a primitive type with only two values — true or false — and the boolean value of an expression is the basis for all JavaScript comparisons and conditions. [S1]
🧠 핵심 개념 (Core concepts)
- Two values only — a Boolean can only have one of two values:
trueorfalse, written in lowercase and without quotes. [S1] - Comparisons return booleans — all JavaScript comparison operators (
==,!=,<,>) returntrueorfalse. [S1] - Drives control flow — booleans are used in
ifstatements and loops to decide which code blocks run. [S1] Boolean()evaluates truthiness — theBoolean()function reports whether an expression or variable is true. [S1]- Truthy vs falsy — everything with a "value" is true; everything without a "value" is false. [S1]
- Avoid Boolean objects — booleans can be created as objects with
new Boolean(), but this should not be done. [S1]
🧩 추출된 패턴 (Extracted patterns)
- Coerce-to-boolean check — wrap an expression in
Boolean(...)(or rely on an expression like(10 > 9)) to obtain its truth value. [S1] - Truthiness rule — empty arrays
[]and empty objects{}are truthy because all objects evaluate to true;0,"",undefined,null,NaN, andfalseare falsy. [S1] - Never compare a primitive boolean to a Boolean object —
(x == y)may be true while(x === y)is false, and two objects always compare as not equal. [S1]
📖 세부 내용 (Details)
The Boolean data type [S1]
In JavaScript, a Boolean is a primitive data type that can only have one of two values: true or false. The boolean value of an expression is the basis for all JavaScript comparisons and conditions. true and false are boolean data types, are the only possible boolean values, and must be written in lowercase and without quotes.
Boolean use cases [S1] Very often, in programming, you will need a data type that can represent one of two values, like: yes or no; on or off; true or false. Boolean values are fundamental for logical operations and control flow.
Comparisons [S1]
All JavaScript comparison operators (like ==, !=, <, >) return true or false. Given that x = 5:
| Description | Example | Returns |
|---|---|---|
| Equal to | (x == 8) | false |
| Not equal to | (x != 8) | true |
| Greater than | (x > 8) | false |
| Less than | (x < 8) | true |
let x = 5;
(x == 8); // equals false
(x != 8); // equals true
Conditions [S1]
Booleans are extensively used in if statements to determine which code blocks to execute.
| Example | Result |
|---|---|
| if (day == "Monday") | true or false |
| if (salary > 9000) | true or false |
| if (age < 18) | true or false |
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
Loops [S1] Booleans are extensively used in loops to determine the looping condition.
| Description | Example |
|---|---|
| For loop | for (i = 0; i < 5; i++) |
| While loop | while (i < 10) |
| For in loop | for (x in person) |
| For of loop | for (x of cars) |
while (i < 10) {
text += i;
i++;
}
The Boolean() function [S1]
You can use the Boolean() function to find out if an expression (or a variable) is true:
Boolean(10 > 9)
Or even easier:
(10 > 9)
Everything with a "value" is true [S1]
The following all evaluate to true: 100, 3.14, -15, true, "Hello", "false", (7 + 1 + 3.14), [ ], { }.
Note: In JavaScript, both an empty array [ ] and an empty object { } are truthy because they are objects. All objects in JavaScript evaluate to true in a boolean context, regardless of their content.
Everything without a "value" is false [S1]
The following all evaluate to false: 0, "", undefined, null, NaN, false.
The boolean value of 0 (zero) is false:
let x = 0;
Boolean(x);
The boolean value of -0 (minus zero) is false:
let x = -0;
Boolean(x);
The boolean value of "" (empty string) is false:
let x = "";
Boolean(x);
The boolean value of undefined is false:
let x;
Boolean(x);
The boolean value of null is false:
let x = null;
Boolean(x);
The boolean value of false is false:
let x = false;
Boolean(x);
The boolean value of NaN is false:
let x = 10 / "Hallo";
Boolean(x);
JavaScript booleans as objects [S1] Normally JavaScript booleans are primitive values created from literals:
let x = false;
But booleans can also be defined as objects with the keyword new:
let y = new Boolean(false);
let x = false;
let y = new Boolean(false);
// typeof x returns boolean
// typeof y returns object
Warning: Do not create Boolean objects. The new keyword complicates the code and slows down execution speed. Boolean objects can produce unexpected results.
Booleans and boolean objects cannot be safely compared:
let x = Boolean(false);
let y = new Boolean(false);
// (x == y) returns true
// (x === y) returns false
Comparing two JavaScript objects always returns false.
🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — comparison results, an if/else greeting, a while accumulation loop, and Boolean() truthiness checks across falsy values. No external project/commit applications found in the source.
💻 코드 패턴 (Code patterns)
Check truthiness of an expression:
Boolean(10 > 9)
Detect a falsy value:
let x = "";
Boolean(x); // false
Avoid Boolean objects (anti-pattern noted by source):
let y = new Boolean(false); // typeof y returns object
⚖️ 모순 및 업데이트 (Contradictions & updates)
No contradictions found in the source. The source explicitly warns against the new Boolean() object form as an anti-pattern.
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.89
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: JavaScript Tutorial
- 관련 개념: JavaScript Comparisons, JavaScript If Else, JavaScript Logical, JavaScript Data Types
- 참조 맥락: Underlies every condition and comparison; central to truthy/falsy reasoning in conditionals and loops.
📚 출처 (Sources)
- [S1] W3Schools — JavaScript Booleans — https://www.w3schools.com/js/js_booleans.asp
📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Booleans" page (Astra wiki-curation, P-Reinforce v3.1 format).