JavaScript Tutorial/Operators/Operator Precedence

Материал из Web эксперт
Версия от 18:52, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Operator order in action

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
alert(3 - 1 * 6);
alert((3 - 1) * 6);
//  -->
</script>
</head>
<body>
</body>
</html>


Operator Precedence from highest to lowest

Read From Operator Operator Name Left to Right . Object property access Left to Right [] Array index Left to Right () Function call Right to Left ++ Pre/Post Increment Right to Left -- Pre/Post Decrement Right to Left - Negation Right to Left ~ Bitwise NOT Right to Left ! Logical NOT Right to Left delete Undefine a property Right to Left new Create a new object Right to Left typeof Return data type Right to Left void Return undefined value Left to Right

  • , /, %

Multiplication, division, modulus Left to Right +, - Addition, Subtraction Left to Right + String concatenation Left to Right << Left shift Left to Right >> Right shift with sign Left to Right >>> Right shift zero fill Left to Right <, <= Less than, less than or equal Left to Right >, >= Greater than, greater than or equal Left to Right == Equality Left to Right != Inequality Left to Right

=

Identity Left to Right !== Non-identity Left to Right & Bitwise AND Left to Right ^ Bitwise XOR Left to Right | Bitwise OR Left to Right && Logical AND Left to Right || Logical OR Right to Left ?: Conditional Right to Left = Assignment Right to Left

  • =, /=

Assignment plus operation %=, +=, -=, <<=, >>=, >>>=, &=, ^=, |= Left to Right . Multiple evaluation