tailieunhanh - Học JavaScript qua ví dụ part 12

Các loại nhà khai thác Toán tử số học Số học điều hành có giá trị số (hoặc các chữ hoặc các biến) như-oper của họ ands và trả lại một giá trị số. Các toán tử số học tiêu chuẩn được cộng (+), trừ (-), nhân (*), và phân chia (/). | About JavaScript Operators and Expressions 85 In Table the operators on the same line are of equal precedence. The rows are in order of highest to lowest precedence. Table Precedence and Associativity Operator Description Associativity 0 Parentheses Left to right Auto increment decrement Right to left Logical NOT Right to left Multiply divide modulus Left to right - Add subtract Left to right Concatenation Left to right Less than less than or equal to Left to right Greater than greater than or equal to Left to right Equal to not equal to Left to right Identical to same type not identical to Left to right Bitwise AND Left to right 1 Bitwise OR A Bitwise XOR Bitwise NOT Bitwise left shift Bitwise right shift Bitwise zero-filled right shift Logical AND Left to right II Logical OR Left to right Ternary conditional Right to left - 1 Assignment Right to left comma From the Library of 86 Chapter 5 Operators EXAMPLE html head title First JavaScript Sample title script type text javascript 1 var result 5 4 12 4 script head body bgcolor yellow text blue big script type text javascript 2 result result br script big body html EXPLANATION 1 The order of associativity is from left to right. Multiplication and division are of a higher precedence than addition and subtraction and addition and subtraction are of higher precedence than assignment. To illustrate this we ll use parentheses to group the operands as they are grouped by JavaScript. In fact if you want to force precedence use the parentheses around the expression to group the operands in the way you want them evaluated. The following two examples produce the same result var result 5 4 12 4 could be written result 5 4 12 4 2 The expression is evaluated and the result is assigned to variable result. The value of result is displayed on the browser see Figure . Figure Output from Example Precedence and associativity. From the Library of About JavaScript

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG