--- id: javascript-comments title: "JavaScript Comments" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS comments", "single line comment", "multi-line comment", "block comment", "prevent execution"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "comments"] raw_sources: ["https://www.w3schools.com/js/js_comments.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Comments]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) JavaScript comments explain code and improve readability β€” single-line comments start with `//`, multi-line comments are wrapped in `/* */`, and either form can also be used to prevent code from executing. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Purpose of comments** β€” comments can be used to explain JavaScript code and to make it more readable; they can also be used to prevent execution when testing alternative code. [S1] - **Single line comments** β€” start with `//`; any text between `//` and the end of the line is ignored (not executed). [S1] - **Multi-line comments** β€” start with `/*` and end with `*/`; any text between is ignored. [S1] - **Comments to prevent execution** β€” placing `//` or `/* */` around code lines is a convenient way to prevent execution, e.g. while debugging. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **End-of-line annotation** β€” append `// ...` after a statement to document what that line does. [S1] - **Block intro comment** β€” use a `/* ... */` block before a group of statements to describe what the following code does. [S1] - **Comment-out for debugging** β€” prefix a single line with `//`, or wrap several lines in `/* */`, to temporarily disable them. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Single Line Comments** β€” Single line comments start with `//`. Any text between `//` and the end of the line will be ignored by JavaScript (will not be executed). This example uses a single line comment before each line of code: [S1] ```javascript // Change heading: document.getElementById("myH").innerHTML = "My First Page"; // Change paragraph: document.getElementById("myP").innerHTML = "My first paragraph."; ``` This example uses a single line comment at the end of each line to explain the code: [S1] ```javascript let x = 5; // Declare x, give it the value of 5 let y = x + 2; // Declare y, give it the value of x + 2 ``` **Multi-line Comments** β€” Multi-line comments start with `/*` and end with `*/`. Any text between `/*` and `*/` will be ignored by JavaScript. This example uses a multi-line comment (a comment block) to explain the code: [S1] ```javascript /* The code below will change the heading with id = "myH" and the paragraph with id = "myP" in my web page: */ document.getElementById("myH").innerHTML = "My First Page"; document.getElementById("myP").innerHTML = "My first paragraph."; ``` **Using Comments to Prevent Execution** β€” Using comments to prevent execution of code is suitable for testing. Adding `//` in front of a code line changes the lines from an executable line to a comment: [S1] ```javascript //document.getElementById("myH").innerHTML = "My First Page"; document.getElementById("myP").innerHTML = "My first paragraph."; ``` This example uses a comment block to prevent execution of multiple lines: [S1] ```javascript /* document.getElementById("myH").innerHTML = "My First Page"; document.getElementById("myP").innerHTML = "My first paragraph."; */ ``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” single-line intro/end-of-line comments, a multi-line explanatory block, and commenting out one line vs a multi-line block to prevent execution. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Single line, end-of-line: ```javascript let x = 5; // Declare x, give it the value of 5 ``` Multi-line block: ```javascript /* This block describes the code below. */ ``` Comment out to disable: ```javascript //document.getElementById("myH").innerHTML = "My First Page"; ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Syntax]], [[JavaScript Statements]], [[JavaScript Variables]] - **μ°Έμ‘° λ§₯락:** Documentation practice referenced across every code example in the tutorial. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Comments β€” https://www.w3schools.com/js/js_comments.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Comments" page (Astra wiki-curation, P-Reinforce v3.1 format).