>=", "> >>=", "&=", "|=", "^="."/> >=", "> >>=", "&=", "|=", "^=".">

Home >Web Front-end >Front-end Q&A >What assignment operators do JavaScript have?

What assignment operators do JavaScript have?

青灯夜游
青灯夜游Original
2021-11-24 17:15:143601browse

The assignment operators of JavaScript are: "=", "=", "-=", "*=", "/=", "%=", "585a560ca204456310ccd7d95fba6612>=", ">>>=", "&=", "|=", "^=".

What assignment operators do JavaScript have?

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.

In JavaScript, the assignment operator is used to assign values ​​to variables. The operand on the left side of an assignment operator must be a variable, object property, or array element, also known as an lvalue.

For example, the following writing is wrong because the value on the left is a fixed value and operations are not allowed.

1 = 100;  //返回错误

The assignment operation has the following two forms:

  • Simple assignment operation =: Directly copy the value of the operand on the right side of the equal sign to the left operand, so the value of the left operand changes.

  • Assignment operation of additional operations: Before assignment, perform some operation on the right operand, and then copy the operation result to the left operand. The specific instructions are as shown in the table:

Unsigned right shift operation and assignment bita >>>= ba = a >>> b##&=##|=a |= ba = a |= b##^=The sample code is as follows:
var x = 10;
x += 20;
console.log(x);  // 输出:30
var x = 12,
    y = 7;
x -= y;
console.log(x);  // 输出:5
x = 5;
x *= 25;
console.log(x);  // 输出:125
x = 50;
x /= 10;
console.log(x);  // 输出:5
x = 100;
x %= 15;
console.log(x);  // 输出:10
Assignment operator for additional operations
Assignment operator Explanation Example Equivalent to
= Addition or concatenation operation and assignment a = b a = a b
-= Subtraction operation and assignment a -= b a= a - b
*= Multiplication and assignment a *= b a = a * b
/= Division operation and assignment a /= b a = a / b
%= Modulo operation and assignment a %= b a = a % b
65630b347a1052c7a251a318e990274d>= Right shift operation and assignment a >>= b a = a >> b
##>>>=
Bitwise AND operation and assignment a &= b a = a & b
Bitwise OR operation and assignment
Bit XOR operation and assignmenta ^= b a = a ^ b
【Related recommendations:

javascript learning tutorial

The above is the detailed content of What assignment operators do JavaScript have?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn