> 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/grammar/op/assign/assignment.md).

# assignment (=)

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

{% hint style="success" %}
([operator](/web/js/grammar/op.md)) <mark style="color:yellow;">**assigns**</mark> [value](/web/js/val.md) to [variable](/web/js/variable.md) <mark style="color:yellow;">**/**</mark> [property](/web/js/val/obj/prop.md) <mark style="color:yellow;">**/**</mark> [element](/web/js/val/builtin/arr/element.md), 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](/web/js/variable/declare/var.md) [<mark style="color:yellow;">**redeclaration**</mark>](/web/js/variable/declare.md)&#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](/web/js/concept/env/js-engine/mode/strict-mode.md):exclamation:
* ⭐️ the <mark style="color:purple;">**assignment (=)**</mark> part is <mark style="color:red;">**applied**</mark>:exclamation:

👉 [var redeclaration applied even in strict mode❗️](/web/js/variable/declare/var/redeclare.md)
{% endhint %}

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

* :exclamation:[accidental global variable in sloppy mode❗️](/web/js/concept/env/js-engine/mode/sloppy-mode/accidental-global-variable-in-sloppy-mode.md) in [sloppy mode](/web/js/concept/env/js-engine/mode/sloppy-mode.md).
* :shield:[⛔️ ReferenceError](/web/js/err/ref.md) ⟩ ['xxx' is not defined❗️](/web/js/err/ref/not-defined.md) in [strict mode](/web/js/concept/env/js-engine/mode/strict-mode.md)
  {% endhint %}

{% hint style="info" %}
the <mark style="color:purple;">**assignment**</mark> of a [**property**](/web/js/val/obj/prop.md) <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**](/web/js/val/obj/proto/chain.md).
{% endhint %}
{% endtab %}

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

* [destructuring assignment](/web/js/grammar/op/assign/destruct.md)
* [dot notation (.)](/web/js/val/obj/prop/access/dot-notation-..md) / [bracket notation \[\]](/web/js/val/obj/prop/access/bracket-notation.md) - assignment of a property
  {% endtab %}

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

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

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

* [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 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 %}
