Chapter 2 Lesson 3 PDF
Chapter 2 Lesson 3 PDF
Chapter 2 Lesson 3 PDF
Chapter 2
Lesson 3
Figure 2-8
Unary Operators
• Two types of unary operators:
– Prefix operators, which are placed before the variable
– Postfix operators, which are placed after the variable
• Prefix operator is applied before assignment operator:
let x = 5;
let y = ++x // x = 6 and y = 6
• Postfix operator is applied after assignment operator:
let x = 5;
let y = x++ // x = 6 and y = 5
Figure 2-9
Assignment Operators
• An assignment operator (e.g., =) is used for assigning a value to a
variable
• Compound assignment operators both assign a value and perform
a calculation
– Interpreter will attempt to convert a nonnumeric to a numeric operand
Figure 2-10
Comparison operators
Comparison operators (relational operators): used to compare two operands
• Two nonnumerical operands are compared in lexicographical order
• String plus number: interpreter converts string to number or returns false
Figure 2-11
Conditional operators
Figure 2-12
Special Operators
Figure 2-6
Figure 2-13
Understanding Operator Precedence
Figure 2-16
Understanding Operator Precedence Continue 2
Figure 2-17
Locating Errors with the Browser Console