Code Highlights logo

Learn

Variables

Mathematical Assignment Operators

Mathematical Assignment Operators are used to perform arithmetic operations and assign the result back to the same variable.

The most common Mathematical Assignment Operators are:

  • Addition Assignment Operator += It adds the value on the right-hand side to the value on the left-hand side and assigns the result back to the variable.

    Example:

    1let num = 10;
    2num += 5; // equivalent to num = num + 5;
    3console.log(num); // Output: 15
  • Subtraction Assignment Operator -= It subtracts the value on the right-hand side from the value on the left-hand side and assigns the result back to the variable.

    Example:

    1let num = 20;
    2num -= 7; // equivalent to num = num - 7;
    3console.log(num); // Output: 13
  • *Multiplication Assignment Operator: = The multiplication assignment operator *= multiplies the value on the right-hand side with the value on the left-hand side and assigns the result back to the variable.

    Example:

    1let num = 5;
    2num *= 4; // equivalent to num = num * 4;
    3console.log(num); // Output: 20

By using these mathematical assignment operators, we can perform arithmetic operations in a concise and efficient manner while assigning the result back to the variable.


Instructions

1.

Declare a new variable sum and assign it the value of x plus y.

2.

Print the value of sum.

3.

Declare a new variable quotient and assign it the value of x divided by y.

4.

Print the value of quotient.

Sign up to start coding

Already have an account?

Sign In

Course content