--- id: javascript-function-invocation title: "JavaScript Function Invocation" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["calling a function", "function invocation", "invoke", "() operator", "calling vs referencing", "function call"] 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", "functions", "invocation"] raw_sources: ["https://www.w3schools.com/js/js_function_invocation.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Function Invocation]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The code inside a function does not run when the function is defined β€” it runs when something *invokes* it, and the `()` operator is what invokes a function. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Definition vs invocation** β€” code inside a function is NOT executed when the function is defined; it executes when "something" invokes the function. [S1] - **Invoke vs call** β€” the term "invoke" is common because a function can be invoked without being called directly. [S1] - **The `()` operator invokes a function** β€” appending parentheses to a function name runs it. [S1] - **Calling vs referencing** β€” `sayHello` refers to the function itself (and returns the function); `sayHello()` refers to the function result (and returns the result). [S1] - **Store the returned value** β€” when a function returns a value you can store it in a variable. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Invoke with `()`** β€” `sayHello()` runs the body and yields its return value; omitting `()` yields the function object instead. [S1] - **Capture the result** β€” `let greeting = sayHello();` keeps the returned value for reuse. [S1] - **Invoke on an event** β€” wire a function to a UI event (e.g. `onclick="showHello()"`) so it runs on interaction. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Calling a Function** β€” a defined function: [S1] ```javascript function sayHello() { return "Hello World"; } ``` The code inside a function is **NOT executed** when the function is **defined**. The code inside a function **will execute** when "something" **invokes** the function. It is common to use the term **invoke**, because a function can be invoked without being called. [S1] Invoke the function with `()`: [S1] ```javascript function sayHello() { return "Hello World"; } sayHello(); ``` **Using the Returned Value** β€” when a function returns a value, you can store the value in a variable: [S1] ```javascript function sayHello() { return "Hello World"; } let greeting = sayHello(); ``` Log the result: [S1] ```javascript function sayHello() { return "Hello World"; } console.log(sayHello()); ``` **Displaying the Result** β€” invoke a function and write its result into the page: [S1] ```javascript

``` **Calling a Function Many Times** β€” the same function can be invoked repeatedly: [S1] ```javascript function sayHello() { return "Hello World"; } let a = sayHello(); let b = sayHello(); let c = sayHello(); ``` A converting function invoked with an argument: [S1] ```javascript // Convert Fahrenheit to Celsius: function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } // Call the toCelcius() function let value = toCelsius(77); ``` **Calling vs Referencing a Function** β€” `() ` invokes; without it you get the function itself: [S1] ```javascript function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } let value = toCelsius; ``` ```javascript function sayHello() { return "Hello World"; } let text = sayHello; ``` This is an important difference: `sayHello` refers to the **function itself** (it returns the function); `sayHello()` refers to the **function result** (it returns the result). The `()` operator invokes a function. [S1] **Functions Can Be Called from Anywhere** β€” define one function and invoke it from another (e.g. on a button click): [S1] ```javascript function sayHello() { return "Hello World"; } function showHello() { document.getElementById("demo").innerHTML = sayHello(); } ``` ```javascript

``` **Common Mistakes** β€” [S1] - **Forgetting Parentheses `()`** β€” `sayHello` does not run the function; you must use `sayHello()`. - **Expecting Return** β€” some functions do not return a value. - **Expecting Output** β€” if a function returns a value, you must display it to see it. ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” invoking `sayHello()`, capturing its return, logging it, writing it to `#demo`, calling it many times, and triggering `showHello()` from a button. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Invoke and capture the result (language: JavaScript): ```javascript let greeting = sayHello(); ``` Reference vs invoke: ```javascript let text = sayHello; // the function itself let result = sayHello(); // the function's result ``` Invoke on a UI event: ```javascript function showHello() { document.getElementById("demo").innerHTML = sayHello(); } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Functions]], [[JavaScript Function Definitions]], [[JavaScript Function Parameters]], [[JavaScript Function Returns]] - **μ°Έμ‘° λ§₯락:** Referenced whenever deciding how and when a defined function's body should actually run. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Function Invocation β€” https://www.w3schools.com/js/js_function_invocation.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Function Invocation" page (Astra wiki-curation, P-Reinforce v3.1 format).