# assignment (=)

[JS](../../..) ⟩ [operator](..) ⟩ [assignment]() ⟩ <mark style="color:blue;">`=`</mark>

{% hint style="success" %}
([..](.. "mention")) <mark style="color:yellow;">**assigns**</mark> [val](../../../val "mention") to [variable](../../../variable "mention") <mark style="color:yellow;">**/**</mark> [prop](../../../val/obj/prop "mention") <mark style="color:yellow;">**/**</mark> [element](../../../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](../../../variable/declare/var "mention") [<mark style="color:yellow;">**redeclaration**</mark>](../../../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](../../../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](../../../variable/declare/var/redeclare "mention")
{% endhint %}

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

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

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

{% tab title="🔴 主題" %}
* [destruct](destruct "mention")
* [dot-notation-.](../../../val/obj/prop/access/dot-notation-. "mention") / [bracket-notation](../../../val/obj/prop/access/bracket-notation "mention") - assignment of a property
{% endtab %}

{% tab title="👥 相關" %}
* [strict-equality](../relational/equal/strict-equality "mention")
* [sloppy-equality](../relational/equal/sloppy-equality "mention")
* [lvalue](../term/lvalue "mention") is a term for  [variable](../../../variable "mention") <mark style="color:yellow;">**/**</mark> [prop](../../../val/obj/prop "mention") <mark style="color:yellow;">**/**</mark> [element](../../../val/builtin/arr/element "mention").
{% endtab %}

{% tab title="📗 參考" %}
* [javascript-the-definitive-guide](../../../../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 %}
