--- id: javascript-statements title: "JavaScript Statements" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS statements", "semicolons", "code blocks", "white space", "JS keywords"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "statements", "semicolons"] raw_sources: ["https://www.w3schools.com/js/js_statements.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Statements]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) A JavaScript program is a list of statements β€” composed of values, operators, expressions, keywords, and comments β€” executed in the order they are written and separated by semicolons. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **A program is a list of statements** β€” a computer program is a list of "instructions" to be "executed" by a computer; in JavaScript these instructions are called statements. [S1] - **What statements are made of** β€” values, operators, expressions, keywords, and comments. [S1] - **Semicolons separate statements** β€” semicolons separate JavaScript statements; multiple statements on one line are allowed when separated by semicolons. [S1] - **White space is ignored** β€” JavaScript ignores multiple spaces; add spaces around operators for readability. [S1] - **Line breaks** β€” for best readability, keep lines under 80 characters and break after an operator. [S1] - **Code blocks** β€” statements can be grouped together in code blocks inside curly brackets `{ ... }`, typically defining functions. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Declare-then-assign sequence** β€” declare variables, then assign and compute across ordered statements. [S1] - **One-line grouping** β€” multiple statements may be packed on a single line with semicolons (`a = 5; b = 6; c = a + b;`). [S1] - **Break-after-operator** β€” when a statement is too long, break the line after an operator. [S1] - **Block grouping** β€” wrap related statements in `{ }` to form a function body executed together. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **JavaScript Programs** β€” A computer program is a list of "instructions" to be "executed" by a computer. In a programming language, these programming instructions are called statements. A JavaScript program is a list of programming statements. In HTML, JavaScript programs are executed by the web browser. [S1] **JavaScript Statements** β€” JavaScript statements are composed of values, operators, expressions, keywords, and comments. This statement tells the browser to write "Hello Dolly." inside an HTML element with `id="demo"`: [S1] ```javascript document.getElementById("demo").innerHTML = "Hello Dolly."; ``` Most JavaScript programs contain many JavaScript statements, executed in the same order as they are written: [S1] ```javascript let x, y, z; // Statement 1 x = 5; // Statement 2 y = 6; // Statement 3 z = x + y; // Statement 4 ``` **Semicolons ;** β€” Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement: [S1] ```javascript let a, b, c; // Declare 3 variables a = 5; // Assign the value 5 to a b = 6; // Assign the value 6 to b c = a + b; // Assign the sum of a and b to c ``` When separated by semicolons, multiple statements on one line are allowed: [S1] ```javascript a = 5; b = 6; c = a + b; ``` **JavaScript White Space** β€” JavaScript ignores multiple spaces. You can add white space to your script to make it more readable. A good practice is to put spaces around operators (`= + - * /`). [S1] **JavaScript Line Length and Line Breaks** β€” For best readability, programmers often like to avoid code lines longer than 80 characters. If a JavaScript statement does not fit on one line, the best place to break it is after an operator: [S1] ```javascript document.getElementById("demo").innerHTML = "Hello Dolly!"; ``` **JavaScript Code Blocks** β€” JavaScript statements can be grouped together in code blocks, inside curly brackets `{...}`. The purpose of code blocks is to define statements to be executed together. One place you will find statements grouped together in blocks is in JavaScript functions: [S1] ```javascript function myFunction() { document.getElementById("demo1").innerHTML = "Hello Dolly!"; document.getElementById("demo2").innerHTML = "How are you?"; } ``` **JavaScript Keywords** β€” JavaScript statements often start with a keyword to identify the JavaScript action to be performed. The following table lists some of the keywords: [S1] | Keyword | Description | |---------|-------------| | var | Declares a variable | | let | Declares a block variable | | const | Declares a block constant | | if | Marks a block of statements to be executed on a condition | | switch | Marks a block of statements to be executed in different cases | | for | Marks a block of statements to be executed in a loop | | function | Declares a function | | return | Exits a function | | try | Implements error handling to a block of statements | JavaScript keywords are reserved words and cannot be used as names for variables. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” the ordered `let x, y, z` / assign / sum statements, the one-line `a = 5; b = 6; c = a + b;`, the operator line break, and the two-statement function block. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Ordered statements: ```javascript let x, y, z; x = 5; y = 6; z = x + y; ``` Code block (function): ```javascript function myFunction() { document.getElementById("demo1").innerHTML = "Hello Dolly!"; document.getElementById("demo2").innerHTML = "How are you?"; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Syntax]], [[JavaScript Comments]], [[JavaScript Variables]] - **μ°Έμ‘° λ§₯락:** Defines the unit of execution referenced by every later control-flow and function topic. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Statements β€” https://www.w3schools.com/js/js_statements.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Statements" page (Astra wiki-curation, P-Reinforce v3.1 format).