> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/func/argument.md).

# argument

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [function](/web/js/val/func.md) ⟩ argument

{% hint style="success" %}
a [value](/web/js/val.md) <mark style="color:yellow;">**passed into**</mark> a [function](/web/js/val/func.md), [parameter](/web/js/val/func/param.md)(s) are <mark style="color:yellow;">**initialized**</mark> to these values.&#x20;
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="info" %}
:scales:[parameter vs. argument](/web/js/val/func/vs-arg.md)
{% endhint %}

{% hint style="warning" %}
:exclamation:[arguments are passed by value❗️](/web/js/val/func/argument/arguments-are-passed-by-value.md)
{% endhint %}
{% endtab %}

{% tab title="👥 相關" %}

* a [function](/web/js/val/func.md) passed into another function as <mark style="color:purple;">**argument**</mark> is called a [callback](/web/js/val/func/kind/callback.md).
* [**...iterable**](/web/js/grammar/op/spread.md) <mark style="color:yellow;">**expands**</mark> an [**iterable**](/web/js/iteration/iterable.md) in places where <mark style="color:purple;">**arguments**</mark> are expected.&#x20;
  {% endtab %}

{% tab title="💈範例" %}

```javascript
// ⭐️ parameters:
//   • lie in function's definition (compile-time)
function foo( param1, param2, ... ) { ... }
//           ╰─── parameters ────╯

// ⭐️ arguments:
//   • values passed into function when called (run-time)
//   • parameters are initialized to these values.
//   • can be different on each call.
foo( 1, 'hello', false );
//  ╰─── arguments ───╯

foo( 2, 'world', false );
//  ╰─── arguments ───╯
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] [JavaScript Tutorial](https://www.javascripttutorial.net/) ⟩ [Understanding JavaScript Pass-By-Value](https://www.javascripttutorial.net/javascript-pass-by-value/)
  {% endtab %}

{% tab title="📘 手冊" %}

* [x] [Argument](https://developer.mozilla.org/en-US/docs/Glossary/Argument)
* [x] [Parameter](https://developer.mozilla.org/en-US/docs/Glossary/Parameter)
* [ ] [the "arguments" object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) - an [array-like](/web/js/val/builtin/arr/array-like.md) object.
  {% endtab %}

{% tab title="🗣 討論" %}

* [Where are arguments positioned in the lexical environment?](https://stackoverflow.com/questions/61208843/where-are-arguments-positioned-in-the-lexical-environment) ⭐️
  {% endtab %}
  {% endtabs %}
