HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

JavaScript Assignment

JavaScript Assignment Operators

Operator Name Description Example
= Simple Assignment Operator Assigns a value to a variable. x = 5;
+= Addition Assignment Operator Adds the value on the right to the variable's current value and assigns the result to the variable. y += 5;
-= Subtraction Assignment Operator Subtracts the value on the right from the variable's current value and assigns the result to the variable. y -= 5;
*= Multiplication Assignment Operator Multiplies the variable's current value by the value on the right and assigns the result to the variable. a *= 2;
/= Division Assignment Operator Divides the variable's current value by the value on the right and assigns the result to the variable. b /= 4;
%= Remainder Assignment Operator Assigns the remainder of dividing the variable's current value by the value on the right to the variabl c %= 7;
**= Exponentiation Assignment Operator Raises the variable to the power of the value on the right and assigns the result to the variable. d **= 3;

Shift Assignment Operators

Operator Name Description Example
<<= Left Shift Assignment The left shift assignment operator shifts the bits of a number to the left by a specified number of positions and assigns the result back to the variable. x <<= 2;
>>= Right Shift Assignment The right shift assignment operator shifts the bits of a number to the right by a specified number of positions and assigns the result back to the variable. x >>= 2;
>>>= Unsigned Right Shift Assignment The unsigned right shift assignment operator shifts the bits of a number to the right by a specified number of positions, filling the leftmost bits with zeros, and assigns the result back to the variable. x >>>= 2;

Bitwise Assignment Operators

Operator Name Description Example
&= Bitwise AND assignment Performs a bitwise AND operation between the left operand and the right operand, and assigns the result to the left operand. x &= y
|= Bitwise OR assignment Performs a bitwise OR operation between the left operand and the right operand, and assigns the result to the left operand. x |= y
^= Bitwise XOR assignment Performs a bitwise XOR (exclusive OR) operation between the left operand and the right operand, and assigns the result to the left operand. x ^= y
<<= Left shift assignment Shifts the bits of the left operand to the left by the number of positions specified by the right operand, and assigns the result to the left operand. x <<= y
>>= Right shift assignment Shifts the bits of the left operand to the right by the number of positions specified by the right operand, and assigns the result to the left operand. x >>= y