What is Operator Precedence in Javascript

What is Operator Precedence in Javascript

Javascript has by default assigned some precedence (priority) to some operators which get executed according to their precedence

Basically, javascript says the compiler which operator should be compiled first or in sequence. Depending on the precedence the direction of the reading element changes.

Here developers get an advantage where they can specify the order of reading or compiling value🎉

For Example : If the logic is this 34 / (2 + 6)

Then the Answer will be 4.25 What goes on in Background

  • The Compiler reads the code from right to left. Because the precedence of ( ... )Grouping Operator is greater precedence than / Division Operator's
  • First the compiler adds 2 and 6 and then uses them as a dividend for 34

If the logic is this 34 / 2 + 6

  • First 34 will be divided into 2 and then the reminder will be added with 6
  • Here / precedence is greater than + Addition operator so the compiler starts reading the code from left

This table Contains all the operators with their precedence in

  • Number 18 is the highest
  • 1 is the lowest

developer.mozilla.org/en-US/docs/Web/JavaSc..

The table includes the operators with there precedence Number