# Is there any order in operators in JavaScript?

## Operator precedence in JS

**Introduction**

Javascript is a programming or scripting language that allows the implementation of features on the web page. You need to have a basic understanding of HTML and CSS to learn JavaScript.In this article, I’m going to talk about the operators in JavaScript.

JavaScript OperatorsJavaScript operators are used to performing particular actions. They can be used to assign values, compare values, combine values, perform arithmetic operators and more. The operators are symbols or keywords.

# Arithmetic operators

Arithmetic operators take numerical values as their operands and return a single numerical value.

- Also, the operator (+)returns the sum of its
**numerical**operands

var a = 10;var b = 20;var sum = a+b;console.log("Summation is "+sum);ExampleSummation is 30Output

According to the addition arithmetic operator, we can understand the behaviour of subtraction(-), multiplication(*), division(/) ,modules(%) and the exponentiation (**) operator.

var a= 10;var b= 20;var c= 25;var d = 2;var multiplication = a*b;console.log("The answer is "+multiplication);var modulas = c%a;console.log("The answer is "+modulas);var power = a**d;console.log("The answer is "+power);ExampleThe answer is 200Output

The answer is 5

The answer is 100

2. The** increment operator adds 1** to the operand and the **decrement operator deducts 1** from it.

*There are two ways to use increment and decrement operators.*

var a= 10;var b= a++;console.log("Result after postincrement "+b);var c= 15;var d = ++c;console.log("Result after preincrement "+d);ExampleResult after postincrement 10Output

Result after preincrement 16

In the first one, the increment is done after assigning 10 to the

b. In the second one first,cis incrementing by 1 and after it is assigned to thed. Also, the decrement operator behaves.

**Operator Precedence**

If we use two or more operators for one variable, sometimes the result would not be the same as we think.

var a = 100+50*3;console.log(a);

To the above example, you can think of 450 as the answer. Because 100+50=150 and 150*3= 450. But the output is 250. What do you think about that?

This is the main point I want to talk about in this article. That is the operator precedence in JavaScript.Although we use the addition sign(+) first, it catches the multiplication first. Now I’ll give you the operator precedence.

This table shows the precedence of the operators. As the multiplication operator is the higher place(in 15th) contrasting to the addition operator the multiplication operator acts first.

In this table, the brackets are the highest position, so if you need to do any operation at first, you need to use brackets. And in some operators, we should consider the associativity, and we have to order our codes go get the output.

**Assignment Operators**

An assignment operator assigns a value to its left operand**(a variable in JavaScript code)** based on the value of its right operand.

1.We use only one equal sign to assign a value to the variable.

var x,y;x=4; //assigns 4 to xy=x;//assigns 4 to yconsole.log("Now y is "+y);ExampleNow y is 4Output

2.The addition assignment operator adds the value of the left and right operands then assigns the sum to the left.

var x = 4;var y = 3;x+=y; //same as x= x+yconsole.log("x is "+x);Examplex is 7Output

It can be also used to concatenate or add two strings together.

var x = "Hi everyone. ";var y = "Welcome to Javascript";x+=y; //same as x= x+yconsole.log(x);ExampleHi everyone. Welcome to JavascriptOutput

Like the addition assignment operator the subtraction, multiplication, division, remainder and exponentiation assignment operators are also having the same process.

var a = 10;var c = 30;var d =15;a *=c; //same as a=a*c :a=10*10console.log("Now a is "+a);d%=a; //d =10%10=5console.log("Now d is "+d);a **=d; //a=a^d: a=10^5console.log("Now a is "+a);ExampleNow a is 100Output

Now d is 5

Now a is 100000

There are more operators like advanced assignment operators, comparison operators, logical and conditional operators in JavaScript. I will talk about them in a future article.

I think you got some idea about how the operators behave in JavaScriprt, and how to use them to get the required output.

Thank you for reading. If you have any questions feel free to the response.