---
description: named variable passed into function, used to import arguments.
---

# parameter

[JS](../..) ⟩ [object](../obj) ⟩ [function]() ⟩ parameter

{% hint style="success" %}
:u6307: synonyms： "<mark style="color:purple;">**formal parameter**</mark>", "<mark style="color:purple;">**function parameter**</mark>"

a <mark style="color:yellow;">**named**</mark> [variable](../../variable "mention") passed into a [](<> "mention"), used to import [argument](argument "mention")(s) into functions.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}
:star: <mark style="color:yellow;">**in JS**</mark>, [arguments-are-passed-by-value](argument/arguments-are-passed-by-value "mention")
{% endhint %}

{% hint style="success" %}
:star: [instantiation](declare/instantiation "mention") - how parameters are stored.
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}
* <mark style="color:yellow;">**types of parameters**</mark>
  * [default-parameter](param/default-parameter "mention") / [initial-value](../../variable/declare/initial-value "mention")
  * [rest-parameters](param/rest-parameters "mention")
  * [destructured](param/destructured "mention")
  * :exclamation:[duplicate](param/duplicate "mention") ( <mark style="color:red;">**not allowed**</mark>**&#x20;**<mark style="color:yellow;">**in**</mark> [<mark style="color:yellow;">**strict mode**</mark>](../../concept/env/js-engine/mode/strict-mode)❗️)
  * :scales:[simple-vs-nonsimple](param/simple-vs-nonsimple "mention")
* <mark style="color:yellow;">**other topics**</mark>
  * :scales:[vs-arg](vs-arg "mention")
  * :beginner:[overload](overload "mention")
  * :beginner:[as-argument](arrow/as-argument "mention")
  * :beginner:[instantiation](declare/instantiation "mention") - how parameters are stored.
  * :beginner:[parameter-scope](../../scope/parameter-scope "mention")
  * :exclamation:[arguments-are-passed-by-value](argument/arguments-are-passed-by-value "mention")
  * :exclamation:[param-by-var](../../variable/declare/var/param-by-var "mention")
{% endtab %}

{% tab title="👥 相關" %}
* [argument](argument "mention")
* [declare](declare "mention")
* [expr](expr "mention")
* [instantiation](declare/instantiation "mention") - how parameters are stored.
{% 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="🗣 討論" %}
* [Where are arguments positioned in the lexical environment?](https://stackoverflow.com/questions/61208843/where-are-arguments-positioned-in-the-lexical-environment) ⭐️
{% endtab %}

{% tab title="📘 手冊" %}
* [x] [Argument](https://developer.mozilla.org/en-US/docs/Glossary/Argument)
* [ ] [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)
* [ ] [SyntaxError: missing formal parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_formal_parameter)
{% endtab %}
{% endtabs %}
