Introduction

In javaScript, operator precedence is an important concept to understand especially when dealing with mathematical equations. If you remember learning in school the acronym P.E.M.D.A.S (Please Excuse MDear Aunt Sally) then this will quickly make sense. If not, the acronym PEMDAS tells you which part of your mathematical expression should be evaluated first.

With PEMDAS, you first work with what is inside the parenthesis, then exponents, next is multiplication, then division, after its addition, and lastly, it is subtraction.

For instance, if we look at the equation below following the rules of PEMDAS:

(5 + 3) * 2 = ?

Since the 5 + 3 is within the parenthesis (PEMDAS), we add those two expressions together, which gives us 8. Then we take that result of 8 and multiply it by 2 (PEMDAS). The final result equals 16.

How This Applies to JavaScript

In JavaScript, operator precedence works pretty much the same way as I showed you above, however, JS has some additional operators such as thetypeof operator, and has explicit rules of operator associativity.

Let’s look at the table below:

Image for post

#javascript #math #programming-languages #web-development #code

What Is Operator Precedence in Javascript?
1.80 GEEK