Đang chuẩn bị liên kết để tải về tài liệu:
Học JavaScript qua ví dụ part 11
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Các nhà khai thác Về khai thác 5,1 JavaScript và biểu thức các đối tượng dữ liệu có thể được thao tác trong một số cách bởi số lượng lớn các nhà khai thác cung cấp bởi JavaScript. Các nhà khai thác là những biểu tượng, ví dụ như +, -, =,, và | chapter 5 Operators 5.1 About JavaScript Operators and Expressions Data objects can be manipulated in a number of ways by the large number of operators provided by JavaScript. Operators are symbols such as - and that produce a result based on some rules. An operator manipulates data objects called operands for example 5 and 4 are operands in the expression 5 4. Operators and operands are found in expressions. An expression combines a group of values to make a new value n 5 4. And when you terminate an expression with a semicolon or a newline you have a complete statement e.g. n 5 4 . 5 var sum new variable operator operand 4 t .L operator operand In the numeric expression 5 4 2 three numbers are combined. The operators are the and - signs. The operands for the sign are 5 and 4. After that part of the expression is evaluated to 9 the expression becomes 9 - 2. After evaluating the complete expression the result is 7. Because the plus and minus operators each manipulate two operands they are called binary operators. If there is only one operand the operator is called a unary operator. If there are three operands it is called a ternary operator. We ll see examples of these operators later in the chapter. The operands can be either strings numbers Booleans or a combination of these. We have already used some of the operators the concatenation operator to join two strings together the typeof operator to determine what data type is being used and the assignment operator used to assign a value to a variable. Now let s look at a plethora of additional JavaScript operators and see how they manipulate their operands. 83 From the Library of WoweBook.Com 84 Chapter 5 Operators 5.1.1 Assignment An assignment statement evaluates the expression on the right side of the equal sign and assigns the result to the variable on the left side of the equal sign. The equal sign is the assignment operator. var total 5 4 var friend Tony total 5 4 t t t variable assignment expression i i I .