--- 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] ```html

Demo JavaScript in Head

A Paragraph

``` **JavaScript in ``** β€” The same function placed in the body section. Placing scripts at the bottom of the `` element improves the display speed. [S1] ```html

Demo JavaScript in Body

A 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).