---
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
<p id="demo"></p>

<script>
function sayHello() {
  return "Hello World";
}

document.getElementById("demo").innerHTML = sayHello();
</script>
```

**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
<p id="demo"></p>
<button onclick="showHello()">Click Me</button>

<script>
function sayHello() {
  return "Hello World";
}

function showHello() {
  document.getElementById("demo").innerHTML = sayHello();
}
</script>
```

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