# assignment (=)

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [operator](https://lochiwei.gitbook.io/web/js/grammar/op) ⟩ [assignment](https://lochiwei.gitbook.io/web/js/grammar/op/assign) ⟩ <mark style="color:blue;">`=`</mark>

{% hint style="success" %}
([..](https://lochiwei.gitbook.io/web/js/grammar/op "mention")) <mark style="color:yellow;">**assigns**</mark> [val](https://lochiwei.gitbook.io/web/js/val "mention") to [variable](https://lochiwei.gitbook.io/web/js/variable "mention") <mark style="color:yellow;">**/**</mark> [prop](https://lochiwei.gitbook.io/web/js/val/obj/prop "mention") <mark style="color:yellow;">**/**</mark> [element](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element "mention"), and <mark style="color:yellow;">**returns**</mark> the <mark style="color:orange;">**assigned**</mark>**&#x20;**<mark style="color:yellow;">**value**</mark>.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
[var](https://lochiwei.gitbook.io/web/js/variable/declare/var "mention") [<mark style="color:yellow;">**redeclaration**</mark>](https://lochiwei.gitbook.io/web/js/variable/declare)&#x20;

* is <mark style="color:red;">**ignored**</mark> and <mark style="color:red;">**won't**</mark> trigger any <mark style="color:yellow;">**error**</mark>, <mark style="color:red;">**even in**</mark> [strict-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode "mention"):exclamation:
* ⭐️ the <mark style="color:purple;">**assignment (=)**</mark> part is <mark style="color:red;">**applied**</mark>:exclamation:

👉 [redeclare](https://lochiwei.gitbook.io/web/js/variable/declare/var/redeclare "mention")
{% endhint %}

{% hint style="warning" %}
⭐️ <mark style="color:purple;">**assignment (=)**</mark> to an [undeclared](https://lochiwei.gitbook.io/web/js/grammar/token/id/undeclared "mention") will result in&#x20;

* :exclamation:[accidental-global-variable-in-sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode "mention") in [sloppy-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/sloppy-mode "mention").
* :shield:[ref](https://lochiwei.gitbook.io/web/js/err/ref "mention") ⟩ [not-defined](https://lochiwei.gitbook.io/web/js/err/ref/not-defined "mention") in [strict-mode](https://lochiwei.gitbook.io/web/js/concept/env/js-engine/mode/strict-mode "mention")
  {% endhint %}

{% hint style="info" %}
the <mark style="color:purple;">**assignment**</mark> of a [**property**](https://lochiwei.gitbook.io/web/js/val/obj/prop) <mark style="color:red;">**always**</mark> <mark style="color:yellow;">**creates**</mark>**/**<mark style="color:yellow;">**sets a property**</mark> in the <mark style="color:orange;">**original**</mark>**&#x20;**<mark style="color:yellow;">**object**</mark>, it <mark style="color:red;">**never**</mark> <mark style="color:yellow;">**modifies objects**</mark> in the [**prototype chain**](https://lochiwei.gitbook.io/web/js/val/obj/proto/chain).
{% endhint %}
{% endtab %}

{% tab title="🔴 主題" %}

* [destruct](https://lochiwei.gitbook.io/web/js/grammar/op/assign/destruct "mention")
* [dot-notation-.](https://lochiwei.gitbook.io/web/js/val/obj/prop/access/dot-notation-. "mention") / [bracket-notation](https://lochiwei.gitbook.io/web/js/val/obj/prop/access/bracket-notation "mention") - assignment of a property
  {% endtab %}

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

* [strict-equality](https://lochiwei.gitbook.io/web/js/grammar/op/relational/equal/strict-equality "mention")
* [sloppy-equality](https://lochiwei.gitbook.io/web/js/grammar/op/relational/equal/sloppy-equality "mention")
* [lvalue](https://lochiwei.gitbook.io/web/js/grammar/op/term/lvalue "mention") is a term for  [variable](https://lochiwei.gitbook.io/web/js/variable "mention") <mark style="color:yellow;">**/**</mark> [prop](https://lochiwei.gitbook.io/web/js/val/obj/prop "mention") <mark style="color:yellow;">**/**</mark> [element](https://lochiwei.gitbook.io/web/js/val/builtin/arr/element "mention").
  {% endtab %}

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

* [javascript-the-definitive-guide](https://lochiwei.gitbook.io/web/master/ref/javascript-the-definitive-guide "mention") ⟩ 4.11 Assignment Expressions
  {% endtab %}

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

* [Expressions and operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) ⟩ [assignment operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators#assignment_operators) ⟩ [Assignment (=)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: 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:

```
GET https://lochiwei.gitbook.io/web/js/grammar/op/assign/assignment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
