> 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/expr/as-variable.md).

# as variable

[JS](/web/js.md) ⟩ [concepts](/web/js/concept.md) ⟩ [expression](/web/js/grammar/statement/expr.md) ⟩ [function expression](/web/js/val/func/expr.md) ⟩ as variable

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

* replit：[assign function expression to variable](https://replit.com/@pegasusroe/assign-function-expression-to-variable#index.js)

```javascript
// ⭐️ the variable to which the "function expression" is assigned:
// -----------------------------------------------------------------------------
//   • will have a `name` property
//   • the name won't change if it's assigned to a different variable.
//   • (implicit name) if function is anonymous, it will be the "variable name".
//   • (explicit name) if function is named, it will be the "function name".

// ⭐️ (anonymous) function expression
//        ╭──── ⭐️ ────╮
const f = function() { }; 
f.name                   // "f" (implicit name = variable name)

const f2 = f;
f2.name;                 // "f" (the `name` won't change❗)

// ⭐️ arrow function
//        ╭─ ⭐️ ─╮
const h = () => {};
h.name;                  // "h" (implicit name also applies to arrow functions)

// ⭐️ (named) function expression
//        ╭────── ⭐️ ───────╮
const g = function game() { };
g.name;                  // "game" (explicit name = function name)

typeof g;       // 'function'
typeof game;    // undefined (`game` is only scoped within the function body❗)
```

{% endtab %}

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

* [ ] [named function expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function#named_function_expression)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/func/expr/as-variable.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
