--- id: javascript-where-to title: "JavaScript Where To" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["script tag", "external JavaScript", "JS placement", "script src", "where to put JavaScript"] 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", "script-tag", "external-js"] raw_sources: ["https://www.w3schools.com/js/js_whereto.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Where To]] ## π― ν μ€ ν΅μ°° (One-line insight) JavaScript can live inside the HTML `
`, the ``, or in a separate external `.js` file referenced with `` tags. [S1] - **`type` is optional** β The `type` attribute is not required; JavaScript is the default scripting language. [S1] - **Functions and events** β Functions are blocks of code executed when called, often triggered by events such as a button click. [S1] - **Placement is flexible** β Scripts can be placed in ``, ``, or both. [S1] - **External files** β JavaScript can be stored in external files and referenced with the `src` attribute on a `` tags. [S1] ```html ``` The `type` attribute is not required; JavaScript is the default scripting language. [S1] **JavaScript Functions and Events** β Functions are blocks of code that are executed when "called for", often triggered by events like a button click. [S1] **JavaScript in `` or ``** β Scripts can be placed in either section, or both. [S1] **JavaScript in ``** β A function placed in the head section, invoked by a button click: [S1] ```htmlA Paragraph
``` **JavaScript in ``** β The same function placed in the body section. Placing scripts at the bottom of the `` element improves the display speed. [S1] ```htmlA Paragraph
``` **External JavaScript** β Scripts can be placed in external files (e.g. `myScript.js`). External scripts are practical when the same code is used in many different web pages. The external file contains the function only, with no ` ``` **External JavaScript Advantages** β Placing scripts in external files: separates HTML and code, makes HTML and JavaScript easier to read and maintain, and cached JavaScript files can speed up page loads. [S1] **External References** β An external script can be referenced in three different ways: with a full URL, with a file path, or without any path. [S1] ```html ``` ```html ``` ```html ``` ## π οΈ μ μ© μ¬λ‘ (Applied in summary) The page's own snippets are the canonical applied examples β embedding a ` ``` Reference an external file: ```html ``` ## βοΈ λͺ¨μ λ° μ λ°μ΄νΈ (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 Introduction]], [[JavaScript Output]], [[JavaScript Syntax]] - **μ°Έμ‘° λ§₯λ½:** Referenced whenever deciding how and where to attach JavaScript to an HTML document. ## π μΆμ² (Sources) - [S1] W3Schools β JavaScript Where To β https://www.w3schools.com/js/js_whereto.asp ## π λ³κ²½ μ΄λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Where To" page (Astra wiki-curation, P-Reinforce v3.1 format).