JavaScript: Operators and Expressions

1,593 views

Published on

Explore JavaScript’s operators and the complex expressions they enable.

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,593
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: next code in section\n
  • DEMO: next code in section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: next code in section\n
  • DEMO: next code in section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • \n
  • \n
  • \n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • DEMO: conditional operator code\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: rest of section, Function Expressions\n
  • DEMO: rest of section, Function Expressions\n
  • DEMO: rest of section, Function Expressions\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • DEMO: rest of section\n
  • JavaScript: Operators and Expressions

    1. 1. Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    2. 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    3. 3. Objectives• Learn about expressions in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    4. 4. Objectives• Learn about expressions in JavaScript• Explore JavaScript’s operators and the complex expressions they enable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    5. 5. Objectives• Learn about expressions in JavaScript• Explore JavaScript’s operators and the complex expressions they enable• Understand the non-operator-based expressions available in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    6. 6. Expressions in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    7. 7. Expressions in JavaScript• Expressions are the building blocks of code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    8. 8. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    9. 9. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    10. 10. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators  Operators combine from one to three operands to a single value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    11. 11. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators  Operators combine from one to three operands to a single value• Simplest expressions are primary expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    12. 12. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators  Operators combine from one to three operands to a single value• Simplest expressions are primary expressions  Literal values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    13. 13. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators  Operators combine from one to three operands to a single value• Simplest expressions are primary expressions  Literal values  Some language keywords Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    14. 14. Expressions in JavaScript• Expressions are the building blocks of code  Any unit of code that JavaScript can evaluate to a value• Can build complex expressions from simpler expressions, using operators  Operators combine from one to three operands to a single value• Simplest expressions are primary expressions  Literal values  Some language keywords  Variable references Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    15. 15. Operator-Based Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    16. 16. Operator-Based Expressions• Not all expressions require operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    17. 17. Operator-Based Expressions• Not all expressions require operators  But you can use operators to build complex expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    18. 18. Operator-Based Expressions• Not all expressions require operators  But you can use operators to build complex expressions• JavaScript has a rich set of operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    19. 19. Operator-Based Expressions• Not all expressions require operators  But you can use operators to build complex expressions• JavaScript has a rich set of operators  Most operators are punctuation: + - && Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    20. 20. Operator-Based Expressions• Not all expressions require operators  But you can use operators to build complex expressions• JavaScript has a rich set of operators  Most operators are punctuation: + - &&  Some are keywords: delete typeof Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    21. 21. Arithmetic Operators andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    22. 22. Arithmetic Operators andExpressions• Perform arithmetic and other operations on numerical values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    23. 23. Arithmetic Operators andExpressions• Perform arithmetic and other operations on numerical values• Result is a single numeric value or NaN Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    24. 24. Arithmetic Operators andExpressions• Perform arithmetic and other operations on numerical values• Result is a single numeric value or NaN• Implicit conversion of non-numeric operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    25. 25. Arithmetic Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    26. 26. Arithmetic Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    27. 27. Arithmetic Operators Operator Description + Addition when used with two operands (x+y) or converts to a number as a unary operator (+x) - Subtraction when used with two operands (x-y) or negation as a unary operator (-x) * Multiplication / Floating-point division % Modulus, which returns the remainder after dividing the operands ++ Increment, which you can use as either a prefix operator (++x) or postfix operator (x++) -- Decrement, which you can use as either a prefix operator (--x) or postfix operator (x--) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    28. 28. Increment and Decrement Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    29. 29. Increment and Decrement Operators• Add or subtract 1 to or from operand Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    30. 30. Increment and Decrement Operators• Add or subtract 1 to or from operand• Convert to a number, perform the operation, and assign new value to variable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    31. 31. Increment and Decrement Operators• Add or subtract 1 to or from operand• Convert to a number, perform the operation, and assign new value to variable  Pre-increment operator: ++x Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    32. 32. Increment and Decrement Operators• Add or subtract 1 to or from operand• Convert to a number, perform the operation, and assign new value to variable  Pre-increment operator: ++x  Post-increment operator: x++ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    33. 33. Increment and Decrement Operators• Add or subtract 1 to or from operand• Convert to a number, perform the operation, and assign new value to variable  Pre-increment operator: ++x  Post-increment operator: x++  Pre-decrement operator: --x Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    34. 34. Increment and Decrement Operators• Add or subtract 1 to or from operand• Convert to a number, perform the operation, and assign new value to variable  Pre-increment operator: ++x  Post-increment operator: x++  Pre-decrement operator: --x  Post-decrement operator: x-- Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    35. 35. Bitwise Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    36. 36. Bitwise Operators and Expressions• Perform low-level bit manipulation of numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    37. 37. Bitwise Operators and Expressions• Perform low-level bit manipulation of numbers  Treat operands as 32 bit, base 2 numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    38. 38. Bitwise Operators and Expressions• Perform low-level bit manipulation of numbers  Treat operands as 32 bit, base 2 numbers• Two types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    39. 39. Bitwise Operators and Expressions• Perform low-level bit manipulation of numbers  Treat operands as 32 bit, base 2 numbers• Two types  Bitwise logical operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    40. 40. Bitwise Operators and Expressions• Perform low-level bit manipulation of numbers  Treat operands as 32 bit, base 2 numbers• Two types  Bitwise logical operators  Bitwise shift operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    41. 41. Bitwise Logical Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    42. 42. Bitwise Logical Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    43. 43. Bitwise Logical Operators Operator Description & Bitwise AND that returns a 1 in each position for which the corresponding bits of both operands are 1s. | Bitwise OR that returns a 1 in each position for which the corresponding bits of either or both operands are 1s. ^ Bitwise XOR that returns a 1 in each position for which the corresponding bits of either, but not both, operands are 1s. ~ Bitwise NOT that inverts the bits of its operand. Applying this operator is equivalent to changing the sign of the number and subtracting one. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    44. 44. Bitwise Shift Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    45. 45. Bitwise Shift Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    46. 46. Bitwise Shift Operators Operator Description << Left shift, which shifts the bits in the first operand to the left by the number of places specified in the second operand, which should be in the range 0 to 31, shifting zeros in from the right. Shifting a value left by one position is equivalent to multiplying by 2. >> Sign-propagating right shift that shifts bits in the first operand to the right by the number of places specified in the second operand, discarding bits shifted off. The bits filled in on the left depend on the sign bit of the original operand in order to preserve the sign of the result. Shifting a value right by one >>> Zero-fill is equivalent to dividing to the position right shift that shifts bitsby 2. right, discarding bits shifted off, and shifting in zeros from the left. Unlike >>, the bits shifted in on the left are always zero, no matter what the sign of the original operand is. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    47. 47. Assignment Operators andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    48. 48. Assignment Operators andExpressions• Assignment operator is a single = sign Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    49. 49. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    50. 50. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element  Operand on left must be an lvalue Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    51. 51. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element  Operand on left must be an lvalue  Operand on right can be any value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    52. 52. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element  Operand on left must be an lvalue  Operand on right can be any value  Value of expression is the right-side value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    53. 53. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element  Operand on left must be an lvalue  Operand on right can be any value  Value of expression is the right-side value• Can be part of a larger expression Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    54. 54. Assignment Operators andExpressions• Assignment operator is a single = sign  Used to assign a new value to a variable, property value, or array element  Operand on left must be an lvalue  Operand on right can be any value  Value of expression is the right-side value• Can be part of a larger expression  (x = y) == 5 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    55. 55. Assignment with OperationOperators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    56. 56. Assignment with OperationOperators Operator Equivalent Expression x += y x = x + y x -= y x = x - y x *= y x = x * y x /= y x = x / y x %= y x = x % y x <<= y x = x << y x >>= y x = x >> y x >>>= y x = x >>> y x &= y x = x & y x ^= y x = x ^ y x |= y x = x | y Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    57. 57. Assignment with OperationOperators Operator Equivalent Expression x += y x = x + y x -= y x = x - y x *= y x = x * y x /= y x = x / y x %= y x = x % y x <<= y x = x << y x >>= y x = x >> y x >>>= y x = x >>> y x &= y x = x & y x ^= y x = x ^ y x |= y x = x | y• x op= y is equivalent to x = x op y Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    58. 58. Assignment with OperationOperators Operator Equivalent Expression x += y x = x + y x -= y x = x - y x *= y x = x * y x /= y x = x / y x %= y x = x % y x <<= y x = x << y x >>= y x = x >> y x >>>= y x = x >>> y x &= y x = x & y x ^= y x = x ^ y x |= y x = x | y• x op= y is equivalent to x = x op y• Potential side effects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    59. 59. Relational Operators andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    60. 60. Relational Operators andExpressions• Test for relationship between operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    61. 61. Relational Operators andExpressions• Test for relationship between operands  Return a Boolean value based on comparison Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    62. 62. Relational Operators andExpressions• Test for relationship between operands  Return a Boolean value based on comparison  Usually use for branching or looping code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    63. 63. Relational Operators andExpressions• Test for relationship between operands  Return a Boolean value based on comparison  Usually use for branching or looping code• Two groups Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    64. 64. Relational Operators andExpressions• Test for relationship between operands  Return a Boolean value based on comparison  Usually use for branching or looping code• Two groups  Equality operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    65. 65. Relational Operators andExpressions• Test for relationship between operands  Return a Boolean value based on comparison  Usually use for branching or looping code• Two groups  Equality operators  Comparison operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    66. 66. Equality and Inequality Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    67. 67. Equality and Inequality Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    68. 68. Equality and Inequality Operators Operator Description == Equality. Returns true if the operands— as implicitly converted, if the types are different—are equal. != Inequality. Returns true if the operands —as implicitly converted, if the types are different—are not equal. === Strict equality. Returns true if the operands are of the same type and are equal. !== Strict inequality. Returns true if the operands are not of the same type and/ or are not equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    69. 69. Evaluating Equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    70. 70. Evaluating Equality1. Same type, test for strict equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    71. 71. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    72. 72. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality  If operands are null and undefined, they are equal Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    73. 73. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality  If operands are null and undefined, they are equal  One a number, one a string: convert the string to a number and test for equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    74. 74. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality  If operands are null and undefined, they are equal  One a number, one a string: convert the string to a number and test for equality  If one is a Boolean, convert to a number and check for equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    75. 75. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality  If operands are null and undefined, they are equal  One a number, one a string: convert the string to a number and test for equality  If one is a Boolean, convert to a number and check for equality  If one is an object and the other is a number or string, convert and check for equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    76. 76. Evaluating Equality1. Same type, test for strict equality2. Not same type, convert and test for equality  If operands are null and undefined, they are equal  One a number, one a string: convert the string to a number and test for equality  If one is a Boolean, convert to a number and check for equality  If one is an object and the other is a number or string, convert and check for equality  All other combinations are not equal Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    77. 77. Evaluating Strict Equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    78. 78. Evaluating Strict Equality1. If operands are different types, not equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    79. 79. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    80. 80. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal.3. If both are Booleans, equal if both true or both false. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    81. 81. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal.3. If both are Booleans, equal if both true or both false.4. If either operand is NaN, not equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    82. 82. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal.3. If both are Booleans, equal if both true or both false.4. If either operand is NaN, not equal.5. If both numbers, equal if values are equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    83. 83. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal.3. If both are Booleans, equal if both true or both false.4. If either operand is NaN, not equal.5. If both numbers, equal if values are equal.6. If both strings, equal if same length and same characters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    84. 84. Evaluating Strict Equality1. If operands are different types, not equal.2. If both values are null or undefined, they are equal.3. If both are Booleans, equal if both true or both false.4. If either operand is NaN, not equal.5. If both numbers, equal if values are equal.6. If both strings, equal if same length and same characters7. If object references, equal if both reference same object. @ http://www.learnnowonline.com Learn More Copyright © by Application Developers Training Company
    85. 85. Comparison Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    86. 86. Comparison Operators• Compare relative values, return Boolean Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    87. 87. Comparison Operators• Compare relative values, return Boolean Operator Description > Greater than. Returns true if the left operand is greater than the right operand. < Less than. Returns true if the left operand is less than the right operand. >= Greater than or equal. Returns true if the left operand is greater than or equal to the right operand. <= Less than or equal. Returns true if the left operand is less than or equal to the right operand. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    88. 88. Logical Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    89. 89. Logical Operators and Expressions• Boolean algebra Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    90. 90. Logical Operators and Expressions• Boolean algebra• Use of AND and OR operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    91. 91. Logical Operators and Expressions• Boolean algebra• Use of AND and OR operators Operator Description && Logical AND. Returns true if both operands are true and false otherwise. || Logical OR. Returns true if either operand is true. ! Logical NOT. Returns false if the single operand is true, otherwise false. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    92. 92. Logical Operators and Expressions• Boolean algebra• Use of AND and OR operators Operator Description && Logical AND. Returns true if both operands are true and false otherwise. || Logical OR. Returns true if either operand is true. ! Logical NOT. Returns false if the single operand is true, otherwise false. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    93. 93. Logical Operators and Expressions• Boolean algebra• Use of AND and OR operators Operator Description && Logical AND. Returns true if both operands are true and false otherwise. || Logical OR. Returns true if either operand is true.• Use short circuiting Returns false if the single operand is ! Logical NOT.• Return values ofotherwise false. true, && and || Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    94. 94. String Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    95. 95. String Operators and Expressions• + is overloaded for string concatenation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    96. 96. String Operators and Expressions• + is overloaded for string concatenation• Kicks in when either operand is a string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    97. 97. String Operators and Expressions• + is overloaded for string concatenation• Kicks in when either operand is a string• += works for concatenation as well Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    98. 98. Special Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    99. 99. Special Operators and Expressions• Conditional operator ?: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    100. 100. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    101. 101. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator , Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    102. 102. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    103. 103. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    104. 104. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    105. 105. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    106. 106. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    107. 107. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator  in operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    108. 108. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator  in operator  instanceof operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    109. 109. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator  in operator  instanceof operator  new operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    110. 110. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator  in operator  instanceof operator  new operator  this operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    111. 111. Special Operators and Expressions• Conditional operator ?:  op1 ? op2 : op3• Comma operator ,  x = 1, y = 2, z = 3;• typeof operator• Others  Member access operators  delete operator  in operator  instanceof operator  new operator  this operator  void operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    112. 112. Characteristics of Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    113. 113. Characteristics of Operators• Number and Type of Operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    114. 114. Characteristics of Operators• Number and Type of Operands  From one to three operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    115. 115. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    116. 116. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    117. 117. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    118. 118. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    119. 119. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    120. 120. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity  Order that JavaScript performs operations of same precedence Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    121. 121. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity  Order that JavaScript performs operations of same precedence  Left-to-right: ((x op y) op z) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    122. 122. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity  Order that JavaScript performs operations of same precedence  Left-to-right: ((x op y) op z)  Right-to-left: (x op (y op z)) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    123. 123. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity  Order that JavaScript performs operations of same precedence  Left-to-right: ((x op y) op z)  Right-to-left: (x op (y op z))• Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    124. 124. Characteristics of Operators• Number and Type of Operands  From one to three operands  Some work with any type, return any type• Precedence  Order in which performs operations  3 + 6 * 2• Operator Associativity  Order that JavaScript performs operations of same precedence  Left-to-right: ((x op y) op z)  Right-to-left: (x op (y op z))• Examples  10 - 4 + 7 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    125. 125. Other Expression Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    126. 126. Other Expression Types• Not all expressions rely on operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    127. 127. Other Expression Types• Not all expressions rely on operators• Some of the most interesting parts of JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    128. 128. Object Initializer Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    129. 129. Object Initializer Expressions• Has the value of the newly created object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    130. 130. Object Initializer Expressions• Has the value of the newly created object• Several ways to create Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    131. 131. Object Initializer Expressions• Has the value of the newly created object• Several ways to create• Easiest is with curly brackets and comma- delimited list of properties and initial values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    132. 132. Property Access Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    133. 133. Property Access Expressions• Provides access to value of object property or array element Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    134. 134. Property Access Expressions• Provides access to value of object property or array element• Two syntaxes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    135. 135. Property Access Expressions• Provides access to value of object property or array element• Two syntaxes  expression.identifier Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    136. 136. Property Access Expressions• Provides access to value of object property or array element• Two syntaxes  expression.identifier  expression[expression] Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    137. 137. Process to Evaluate Access Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    138. 138. Process to Evaluate Access1. Evaluate expression before . or [ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    139. 139. Process to Evaluate Access1. Evaluate expression before . or [  If null or undefined, throw error Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    140. 140. Process to Evaluate Access1. Evaluate expression before . or [  If null or undefined, throw error2. If not an object or array, convert the value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    141. 141. Process to Evaluate Access1. Evaluate expression before . or [  If null or undefined, throw error2. If not an object or array, convert the value3. If uses the . notation with identifier Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    142. 142. Process to Evaluate Access1. Evaluate expression before . or [  If null or undefined, throw error2. If not an object or array, convert the value3. If uses the . notation with identifier  Retrieve value of property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    143. 143. Process to Evaluate Access1. Evaluate expression before . or [  If null or undefined, throw error2. If not an object or array, convert the value3. If uses the . notation with identifier  Retrieve value of property4. If use the [] notation, evaluate expression and read property or array element Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    144. 144. Invocation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    145. 145. Invocation Expressions• Syntax for calling or executing a function or method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    146. 146. Invocation Expressions• Syntax for calling or executing a function or method• General syntax Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    147. 147. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    148. 148. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    149. 149. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    150. 150. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method• Process Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    151. 151. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method• Process 1. Evaluate function or method and throw error if not callable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    152. 152. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method• Process 1. Evaluate function or method and throw error if not callable 2. Evaluate argument expressions and assign to parameters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    153. 153. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method• Process 1. Evaluate function or method and throw error if not callable 2. Evaluate argument expressions and assign to parameters 3. Perform operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    154. 154. Invocation Expressions• Syntax for calling or executing a function or method• General syntax  func(x, y, z)  obj.meth(x, y, z)• Difference between function and a method• Process 1. Evaluate function or method and throw error if not callable 2. Evaluate argument expressions and assign to parameters 3. Perform operations 4. If return, that becomes value of the function or method. Otherwise undefined. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    155. 155. Object Creation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    156. 156. Object Creation Expressions• Creates a new instance of an object in memory Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    157. 157. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    158. 158. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    159. 159. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    160. 160. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5)  new String("AppDev") Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    161. 161. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5)  new String("AppDev")  new Boolean(true) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    162. 162. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5)  new String("AppDev")  new Boolean(true)  new Object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    163. 163. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5)  new String("AppDev")  new Boolean(true)  new Object  new Rectangle(3, 4, 5, 6) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    164. 164. Object Creation Expressions• Creates a new instance of an object in memory  Invokes a constructor function• Samples  new Number(5)  new String("AppDev")  new Boolean(true)  new Object  new Rectangle(3, 4, 5, 6)  new Date() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    165. 165. Evaluation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    166. 166. Evaluation Expressions• Ability to interpret strings of code on the fly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    167. 167. Evaluation Expressions• Ability to interpret strings of code on the fly• Use the global function eval() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    168. 168. Evaluation Expressions• Ability to interpret strings of code on the fly• Use the global function eval()• Takes a single string as argument Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    169. 169. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    170. 170. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    171. 171. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    172. 172. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!• Learn more about JavaScript on SlideShare! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    173. 173. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!• Learn more about JavaScript on SlideShare! • Introduction to JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    174. 174. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!• Learn more about JavaScript on SlideShare! • Introduction to JavaScript • JavaScript: Values, Types, and Variables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

    ×