> 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/name/anonymous-function.md).

# anonymous function

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [function](/web/js/val/func.md) ⟩ [name](/web/js/val/func/name.md) ⟩ <mark style="color:purple;">**anonymous function**</mark>

{% hint style="success" %}
a [function](/web/js/val/func.md) <mark style="color:red;">**without**</mark> a [function name](/web/js/val/func/name.md).
{% endhint %}

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

```javascript
// ⭐️ anonymous functions
// ╭─── 🔸 ───╮
  (function(){});    // function expression
                     // ⭐️ Note: "()" are required❗️
// ╭─ 🔸 ─╮
   () => {};         // arrow function

// ⭐️ Note:
//   function declaration, can't be anonymous❗️ 
function(){}
// ⛔ SyntaxError: Function statements require a function name
```

{% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="danger" %}

* <mark style="color:red;">**only**</mark> [function expression](/web/js/val/func/expr.md) <mark style="color:green;">**can be**</mark>**&#x20;**<mark style="color:purple;">**anonymous**</mark>.
* <mark style="color:yellow;">**function declarations**</mark> <mark style="color:red;">**must have a name**</mark>.
  {% endhint %}
  {% endtab %}

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

* [ ] [different types of functions](https://developer.mozilla.org/en-US/docs/Glossary/Function#different_types_of_functions)
* [ ] [Function declaration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)
* [ ] [Function expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function)
  {% endtab %}

{% tab title="🚧 " %}
{% hint style="warning" %}
what is a function declaration?
{% endhint %}
{% endtab %}
{% endtabs %}
