Assignment Operator in JavaScript

We have already discussed the ECMA Script in our previous blog tutorial. So, here wo would clearly get a more into deep concept on ECMA script with assignment operators in JavaScript. ECMA scripts are the standardized set of programming state that is used to make the programming code and structure more apparent and beautifully structured.

What are assignment operators?

In JavaScript assignment operators are used to assign the values against any variable we declared. Assignment operators are of generally two types.

Following are the two basic types of assignment operators.

  • Simple assignment Operator
  • Compound assignment Operator

What is Simple Assignment Operator in JavaScript?

In JavaScript programming language, simple assignment operator is referred to “=” operator to help assigning the value in JavaScript.
There is a huge difference between “=” and “== “. “=” is referred to simple assignment operator and is used to assign the value to the variable on the left side of the = operator. Whereas, == is not an assignment operator but it is a comparison operator which is used to compare the two values in JavaScript programming language.
For example,

y=x //Here I am assigning the value of x to y so y would be 10

//Here I am trying to compare the two values with each other like I want to check if the value stored //in x is equals to the value stored in y

What is Compound Assignment Operator in JavaScript?

In JavaScript programming language, compound assignment operators are the operators that includes or involves the arithmetic operations of addition and subtractions as well. Compound assignment operators are generally denoted by “+=” or “-=”.
In += assignment operator we generally do the two steps work in a single step. For example I want to assign a value to a variable with an increment of 3 I would do it in one single step instead of assigning a simple value to a variable first and then adding three to it and storing it.
A good programmer always write short codes for bigger problems to improve the runtime speed of the software.

In -= assignment operator in JavaScript, the value is decreased or subtracted by the value desired and is stored then in a very single step.

There might be a question rise into your mind. Is += and =+ are same?

Buy on amazon with upto 40% off


What is javascript?

Variables in javascript

Leave a Reply

Your email address will not be published. Required fields are marked *