--- id: javascript-assignment title: "JavaScript Assignment" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS assignment operators", "compound assignment", "logical assignment", "falsy values", "truthy values", "nullish coalescing assignment", "spread operator"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "assignment", "operators"] raw_sources: ["https://www.w3schools.com/js/js_assignment.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Assignment]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Assignment operators assign values to variables β€” `=` for a plain assignment and compound forms (`+=`, `-=`, `*=`, `**=`, `/=`, `%=`) plus logical forms (`&&=`, `||=`, `??=`) for assign-and-operate in one step. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Assignment operators assign values** β€” they assign values to JavaScript variables. [S1] - **Compound assignment** β€” arithmetic compound operators combine an operation with assignment, e.g. `x += y` is the same as `x = x + y`. [S1] - **Logical assignment** β€” `&&=`, `||=`, and `??=` assign conditionally based on truthiness/falsiness/nullishness. [S1] - **8 falsy values** β€” `false`, `0`, `-0`, `0n`, `""` (empty strings), `null`, `undefined`, and `NaN` are falsy. [S1] - **Truthy surprises** β€” `"0"`, `"false"`, `[]`, and `{}` are truthy even though they look "empty". [S1] - **Spread `...`** β€” the `...` operator splits iterables into individual elements. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Mutate in place** β€” apply an operation to a variable and store back with one compound operator (`x += 5`). [S1] - **Conditional assignment** β€” `x ??= 10` assigns only when `x` is null/undefined; `x ||= 10` when falsy; `x &&= 10` when truthy. [S1] - **Falsy check awareness** β€” remember `"0"` and `"false"` strings (and `[]`/`{}`) are truthy when writing conditions. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **JavaScript Assignment Operators** [S1] Assignment operators assign values to JavaScript variables. Using `x = 10` and `y = 5` for the examples below, the result column shows the value after applying the operator: | Operator | Example | Same As | Result | |----------|---------|---------|--------| | = | x = y | x = y | x = 5 | | += | x += y | x = x + y | x = 15 | | -= | x -= y | x = x - y | x = 5 | | *= | x *= y | x = x * y | x = 50 | | **= | x **= y | x = x ** y | x = 100000 | | /= | x /= y | x = x / y | x = 2 | | %= | x %= y | x = x % y | x = 0 | **The = Operator** [S1] ```javascript let x = 10; ``` **The += Operator** [S1] ```javascript let x = 10; x += 5; ``` **The -= Operator** [S1] ```javascript let x = 10; x -= 5; ``` **The *= Operator** [S1] ```javascript let x = 10; x *= 5; ``` **The **= Operator** [S1] ```javascript let x = 10; x **= 5; ``` **The /= Operator** [S1] ```javascript let x = 10; x /= 5; ``` **The %= Operator** [S1] ```javascript let x = 10; x %= 5; ``` **Logical Assignment Operators** [S1] The `&&=` Operator (Logical AND assignment): ```javascript let x = true; let y = x &&= 10; ``` The `||=` Operator (Logical OR assignment): ```javascript let x = false; let y = x ||= 10; ``` The `??=` Operator (Nullish Coalescing assignment): ```javascript let x; x ??= 10; ``` **The 8 FALSY Values** [S1] The following values are falsy: `false`, `0`, `-0`, `0n`, `""` / `''` / `` (empty strings), `null`, `undefined`, and `NaN`. **These are TRUTHY** [S1] The following values are truthy: `"0"` (string), `"false"` (string), `[]` (empty array), and `{}` (empty object). **The Spread (...) Operator** [S1] The `...` operator splits iterables into individual elements. ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” each compound operator demonstrated against `let x = 10`, and the logical-assignment operators shown against boolean/undefined seeds. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Compound arithmetic assignment: ```javascript let x = 10; x += 5; ``` Nullish-coalescing assignment (only assigns when null/undefined): ```javascript let x; x ??= 10; ``` Logical OR assignment (assigns when falsy): ```javascript let x = false; let y = x ||= 10; ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. Worth noting: `"0"`, `"false"`, `[]`, and `{}` are truthy despite intuition, which the source explicitly flags. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Operators]], [[JavaScript Arithmetic]], [[JavaScript Comparisons]], [[JavaScript Types]] - **μ°Έμ‘° λ§₯락:** Referenced whenever updating a variable's value or doing conditional/defaulting assignment. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Assignment β€” https://www.w3schools.com/js/js_assignment.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Assignment" page (Astra wiki-curation, P-Reinforce v3.1 format).