Operator precedence describes the order in which operations are performed when an expression is evaluated. Operations with a higher precedence are performed before those with a lower precedence. For example, multiplication is performed before addition.
The following table lists the JavaScript operators, ordered from highest to lowest precedence. Operators with the same precedence are evaluated left to right.
Operator
Description
. [ ] ( )
Field access, array indexing, function calls, and expression grouping
++ -- - ~ ! delete new typeof void
Unary operators, return data type, object creation, undefined values
* / %
Multiplication, division, modulo division
+ - +
Addition, subtraction, string concatenation
<< >> >>>
Bit shifting
< <= > >= instanceof
Less than, less than or equal, greater than, greater than or equal, instanceof
== != === !==
Equality, inequality, strict equality, and strict inequality
&
Bitwise AND
^
Bitwise XOR
|
Bitwise OR
&&
Logical AND
||
Logical OR
?:
Conditional
= OP=
Assignment, assignment with operation (such as += and &=)
,
Multiple evaluation
Parentheses are used to alter the order of evaluation determined by operator precedence. This means an expression within parentheses is fully evaluated before its value is used in the remainder of the expression.
Example1
var result = 78 * 96 + 3;
document.write(result);
document.write("<br/>");
result = 78 * (9 + 3);
document.write(result);
// Output:
// 7491
// 936
Example2
var num = 10;
if(5 == num / 2 && (2 + 2 * num).toString() === "22") {
document.write(true);
}
// Output:
// true
Comments 2