Assignment Operators in Javascript

Javascript Assignment operators

As the name suggests, these are the symbols used for assignment purposes. Well, these are not assignments related to our school or college, but the assignment of values to some variable. If you observe carefully, the first assignment operator symbol, which is ”=”, is being used for quite a long. This is a simple assignment operator, where we are just assigning some value to some variable.

Assignment Operators in Javascript

There are some other symbols as well, through which we can do different things like add and assign, subtract and assign, multiply and assign, etc. Have a look at the below-mentioned assignment operator symbols, and we are also going to consider some examples, to better understand the assignment operators in Javascript.

OperatorDescription
=This operator is used for assignment
+=This is referred to as add and assign
-=This is referred to as subtracting and assigning
*=This is referred to as multiply and assign
/=This is referred to as divide and assign
%=This is referred to as modulus and assign
**=This is referred to as power and assign

As mentioned earlier, let’s now have a look at some programs, through which, we can get an idea about what are assignment operators in Javascript.

We have been using the equals to sign, to assign some value to some variable. So, this is the assignment thing, and in the above program, we have used some of the assignment operators in Javascript, which mean some different things, like add and assign, subtract and assign, and much more. Now, let’s have a look at the output –

As you can see, things went according to what we had set for the operators. We have been using the simple assignment operator for a long right? And now we are even used to it. Just like that, we will get used to the other operators as well, when we start using them on a quite regular basis. Now, let’s move on to have a look at other operators as well.