JavaScript Assignment Operators

The assignment operation evaluates the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables

Name

Description

Syntax

Example

Assignment (=)

This operator assigns the right operand value to the left operand.

If A = 10 and Y = A then Y = 10

Try

Addition Assignment (+=)

Sums up left and right operand values and then assigns the result to the left operand.

Y += 1 gives Y = Y + 1

Try

Subtraction Assignment (- =)

It subtracts the right side value from the left side value and then assigns the result to the left operand. 

Y -= 1 gives Y = Y – 1

Try

Multiplication Assignment (*=)

It multiplies a variable by the value of the right operand and assigns the result to the variable.

Y *= A is equivalent to Y = Y * A

Try

Division Assignment (/ =)

It divides a variable by the value of the right operand and assigns the result to the variable.

Y /= A is equivalent to Y = Y / A

Try

Modules/Remainder Assignment (% =)

It divides a variable by the value of the right operand and assigns the remainder to the variable.

Y %= A is equivalent to Y = Y % A

Try

Exponentiation Assignment (** =)

This raises the value of a variable to the power of the right operand.

Y **= A is equivalent to Y=Y ** A

Try

Left Shift Assignment (<< =)

It moves the specified amount of bits to the left and assigns the result to the variable.

Y <<= A is equivalent to Y=Y << A

Try

Right Shift Assignment (>> =)

It moves the specified amount of bits to the right and assigns the result to the variable.

Y >>= A is equivalent to Y = Y >> A

Try

Bitwise AND Assignment (& =)

: It does a bitwise AND operation on the operand, and assigns the result to the variable.

Y &= b is equivalent to Y = Y & A

Try

Bitwise OR Assignment (| =)

It does a bitwise OR operation on the operand, and assigns the result to the variable.

Y |= A is equivalent to Y= Y | b

Try

Bitwise XOR Assignment (^ =)

It does a bitwise XOR operation on the operand, and assigns the result to the variable.

Y ^= A is equivalent to Y= Y ^ A

Try

JavaScript Operators

JavaScript operators are symbols used to perform specific mathematical, comparison, assignment, and logical computations on operands. They are fundamental elements in JavaScript programming, allowing developers to manipulate data and control program flow efficiently. Understanding the different types of operators and how they work is important for writing effective and optimized JavaScript code.

JavaScript Operators: There are various operators supported by JavaScript.

Table of Content

  • JavaScript Arithmetic Operators
  • JavaScript Assignment Operators
  • JavaScript Comparison Operators
  • JavaScript Logical Operators
  • JavaScript Bitwise Operators
  • JavaScript Ternary Operators
  • JavaScript Comma Operators
  • JavaScript Unary Operators
  • JavaScript Relational Operators
  • JavaScript BigInt Operators
  • JavaScript String Operators

Similar Reads

JavaScript Arithmetic Operators

JavaScript Arithmetic Operators perform arithmetic operations: addition (+), subtraction (-), multiplication (*), division (/), modulus (%), and exponentiation (**)....

JavaScript Assignment Operators

The assignment operation evaluates the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables...

JavaScript Comparison Operators

Comparison operators are mainly used to perform the logical operations that determine the equality or difference between the values....

JavaScript Logical Operators

JavaScript Logical Operators perform logical operations: AND (&&), OR (||), and NOT (!), evaluating expressions and returning boolean values....

JavaScript Bitwise Operators

The bitwise operator in JavaScript is used to convert the number to a 32-bit binary number and perform the bitwise operation. The number is converted back to the 64-bit number after the result....

JavaScript Ternary Operators

The ternary operator has three operands. It is the simplified operator of if/else....

JavaScript Comma Operators

Comma Operator (,) mainly evaluates its operands from left to right sequentially and returns the value of the rightmost operand....

JavaScript Unary Operators

A unary operation is an operation with only one operand....

JavaScript Relational Operators

JavaScript Relational operators are used to compare its operands and determine the relationship between them. They return a Boolean value (true or false) based on the comparison result....

JavaScript BigInt Operators

JavaScript BigInt operators support arithmetic operations on BigInt data type, including addition, subtraction, multiplication, division, and exponentiation. Most operators that can be used between numbers can be used between BigInt values as well....

JavaScript String Operators

JavaScript String Operators include concatenation (+) and concatenation assignment (+=), used to join strings or combine strings with other data types....

Conclusion

JavaScript operators are essential tools that empower developers to perform a wide array of operations on data, from simple arithmetic to complex logical decisions. By mastering these operators, you can write more efficient, readable, and maintainable code. Whether you’re performing calculations, making comparisons, assigning values, or manipulating data, understanding how to use JavaScript operators effectively is a fundamental skill for any JavaScript developer. As you continue to build your programming expertise, the versatility and power of operators will become increasingly apparent, enabling you to create more dynamic and robust applications....