Sunday, 24 July 2016

JavaScript Operator Precedence

Operator Precedence
Operators are used to perform various task, such as calculation, making decision etc.
The combination  of operators and operands form expressions. Expressions are evaluated in the order of high to low precedence.
Below table showing operators in the decreasing order of precedence from top to bottom and left to right.
Operator Type
Individual Operator
member
., []
New
new
function call
()
Increment
++
Decrement
--
Logical-not
!
Bitwise not
~
Unary +
+
Unary negation
-
typeof
typeof
void
void
Delete
delete
Multiplication
*
Division
/
Modulus
%
Addition
+
Subtraction
-
Bitwise shift
<<, >>, >>>
Relational
<, <=, >, >=
In
in
instanceof
instanceof
Equality
==, !=, ===, !==
Bitwise-and
&
Bitwise-xor
^
Bitwise-or
|
Logical-and
&&
Logical-or
||
Conditional
?:
Assignment
=, +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, ^=, |=
Comma
,




example
<!DOCTYPE html>
<html>
<head>
    <title>javaScript Operator Precedence</title>
</head>
<body>
    <h1>JavaScript Operator Precedence</h1>
    <script>
        document.write("2 * 3 / 6 + 4 - 4 : Result : " + (2 * 3 / 6 + 4 - 4) + "<br />");
        document.write("(2 * (3 / 6 + 4) - 4) : Result : " + (2 * (3 / 6 + 4) - 4) + "<br />");
        document.write("((2 * 3 / 6 + 4) - 4) : Result : " + ((2 * 3 / 6 + 4) - 4) + "<br />");
    </script>
</body>
</html>



0 comments:

Post a Comment