What are Assignment Operators in Javascript

Description

Simple assignment is = as shown in the following example.

var num = 1;

Compound assignment operators are shorthand for the simple assignment.


var num = 1;
num = num + 1;
console.log(num);

The second line of code can be replaced with a compound assignment:


var num = 1;
num += 1;
console.log(num);

Compound-assignment operators in Javascript are as follows:

  • Multiply/assign (*=)
  • Divide/assign (/=)
  • Modulus/assign (%=)
  • Add/assign (+=)
  • Subtract/assign (-=)
  • Left shift/assign (<<=)
  • Signed right shift/assign (>>=)
  • Unsigned right shift/assign (>>>=)




















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions