SlideShare uma empresa Scribd logo
1 de 174
Operators and Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Objectives




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Objectives
• Learn about expressions in JavaScript




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
Expressions in JavaScript




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Expressions in JavaScript
• Expressions are the building blocks of code




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
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
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
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
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
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
Operator-Based Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Operator-Based Expressions
• Not all expressions require operators




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
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
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
Arithmetic Operators and
Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Arithmetic Operators and
Expressions
• Perform arithmetic and other operations on
  numerical values




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Arithmetic Operators and
Expressions
• 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
Arithmetic Operators and
Expressions
• 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
Arithmetic Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Arithmetic Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
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
Increment and Decrement Operators




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Increment and Decrement Operators

• Add or subtract 1 to or from operand




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
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
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
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
Bitwise Operators and Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Bitwise Operators and Expressions
• Perform low-level bit manipulation of numbers




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
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
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
Bitwise Logical Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Bitwise Logical Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
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
Bitwise Shift Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Bitwise Shift Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
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
Assignment Operators and
Expressions




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Assignment Operators and
Expressions

• Assignment operator is a single = sign




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Assignment Operators and
Expressions

• 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
Assignment Operators and
Expressions

• 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
Assignment Operators and
Expressions

• 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
Assignment Operators and
Expressions

• 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
Assignment Operators and
Expressions

• 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
Assignment Operators and
Expressions

• 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
Assignment with Operation
Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Assignment with Operation
Operators
       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
Assignment with Operation
Operators
           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
Assignment with Operation
Operators
           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
Relational Operators and
Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Relational Operators and
Expressions
• Test for relationship between operands




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Relational Operators and
Expressions
• Test for relationship between operands
   Return a Boolean value based on comparison




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Relational Operators and
Expressions
• 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
Relational Operators and
Expressions
• 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
Relational Operators and
Expressions
• 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
Relational Operators and
Expressions
• 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
Equality and Inequality Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Equality and Inequality Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
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
Evaluating Equality




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Evaluating Equality
1. Same type, test for strict equality




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Evaluating Equality
1. Same type, test for strict equality
2. Not same type, convert and test for equality




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Evaluating Equality
1. Same type, test for strict equality
2. 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
Evaluating Equality
1. Same type, test for strict equality
2. 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
Evaluating Equality
1. Same type, test for strict equality
2. 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
Evaluating Equality
1. Same type, test for strict equality
2. 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
Evaluating Equality
1. Same type, test for strict equality
2. 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
Evaluating Strict Equality




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Evaluating Strict Equality
1. If operands are different types, not equal.




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Evaluating Strict Equality
1. 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
Evaluating Strict Equality
1. 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
Evaluating Strict Equality
1. 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
Evaluating Strict Equality
1. 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
Evaluating Strict Equality
1. 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
Evaluating Strict Equality
1. 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
7. If object references, equal if both reference
   same object. @ http://www.learnnowonline.com
           Learn More
             Copyright © by Application Developers Training Company
Comparison Operators




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Comparison Operators
• Compare relative values, return Boolean




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
Logical Operators and Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Logical Operators and Expressions
• Boolean algebra




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Logical Operators and Expressions
• Boolean algebra
• Use of AND and OR operators




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
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
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
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
String Operators and Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
String Operators and Expressions
• + is overloaded for string concatenation




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
Special Operators and Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Special Operators and Expressions
• Conditional operator ?:




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Operators and Expressions
• Conditional operator ?:
    op1 ? op2 : op3




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Special Operators and Expressions
• Conditional operator ?:
    op1 ? op2 : op3
• Comma operator ,




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
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
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
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
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
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
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
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
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
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
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
Characteristics of Operators




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Characteristics of Operators
• Number and Type of Operands




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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
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
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
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
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
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
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
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
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
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
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
Other Expression Types




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Other Expression Types
• Not all expressions rely on operators




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
Object Initializer Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Object Initializer Expressions
• Has the value of the newly created object




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
Property Access Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
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
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
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
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
Process to Evaluate Access




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [
   If null or undefined, throw error




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [
   If null or undefined, throw error
2. If not an object or array, convert the value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [
   If null or undefined, throw error
2. If not an object or array, convert the value
3. If uses the . notation with identifier




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [
   If null or undefined, throw error
2. If not an object or array, convert the value
3. If uses the . notation with identifier
   Retrieve value of property




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Process to Evaluate Access
1. Evaluate expression before . or [
   If null or undefined, throw error
2. If not an object or array, convert the value
3. If uses the . notation with identifier
   Retrieve value of property
4. If use the [] notation, evaluate expression and
   read property or array element




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Invocation Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Invocation Expressions
• Syntax for calling or executing a function or method




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
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
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
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
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
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
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
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
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
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
Object Creation Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Object Creation Expressions
• Creates a new instance of an object in memory




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
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
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
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
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
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
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
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
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
Evaluation Expressions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Evaluation Expressions
• Ability to interpret strings of code on the fly




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
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
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
Learn More!




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
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
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
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
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
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

Mais conteúdo relacionado

Mais procurados

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
Jin Castor
 

Mais procurados (20)

Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Javascript
JavascriptJavascript
Javascript
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
JavaScript Control Statements II
JavaScript Control Statements IIJavaScript Control Statements II
JavaScript Control Statements II
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Clean Code
Clean CodeClean Code
Clean Code
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
C# basics
 C# basics C# basics
C# basics
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Terraform tfstate
Terraform tfstateTerraform tfstate
Terraform tfstate
 
TypeScript
TypeScriptTypeScript
TypeScript
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 

Semelhante a JavaScript: Operators and Expressions

Semelhante a JavaScript: Operators and Expressions (20)

.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data Types
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow control
 
Asynchronous Programming
Asynchronous ProgrammingAsynchronous Programming
Asynchronous Programming
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVC
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniques
 
Web API HTTP Pipeline
Web API HTTP PipelineWeb API HTTP Pipeline
Web API HTTP Pipeline
 
WPF Binding
WPF BindingWPF Binding
WPF Binding
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET Framework
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVC
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQuery
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collections
 
SQL Server: Security
SQL Server: SecuritySQL Server: Security
SQL Server: Security
 
Generics
GenericsGenerics
Generics
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud DayRole of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
Role of DBAs in CLOUD ERA - AIOUG Hyd Chapter - Oracle Cloud Day
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 

Mais de LearnNowOnline

Mais de LearnNowOnline (14)

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data Protection
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with Data
 
A tour of SQL Server
A tour of SQL ServerA tour of SQL Server
A tour of SQL Server
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document Management
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPath
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction Design
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User Interface
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Último (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

JavaScript: Operators and Expressions

  • 1. Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Objectives • Learn about expressions in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. Expressions in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7. Expressions in JavaScript • Expressions are the building blocks of code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. 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. Operator-Based Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16. Operator-Based Expressions • Not all expressions require operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. Arithmetic Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. Arithmetic Operators and Expressions • Perform arithmetic and other operations on numerical values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23. Arithmetic Operators and Expressions • 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. Arithmetic Operators and Expressions • 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. Arithmetic Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. Arithmetic Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Increment and Decrement Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. Bitwise Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. Bitwise Logical Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42. Bitwise Logical Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Bitwise Shift Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45. Bitwise Shift Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Assignment Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48. Assignment Operators and Expressions • Assignment operator is a single = sign Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49. Assignment Operators and Expressions • 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. Assignment Operators and Expressions • 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. Assignment Operators and Expressions • 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. Assignment Operators and Expressions • 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. Assignment Operators and Expressions • 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. Assignment Operators and Expressions • 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. Assignment with Operation Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56. Assignment with Operation Operators 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. Assignment with Operation Operators 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. Assignment with Operation Operators 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. Relational Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60. Relational Operators and Expressions • Test for relationship between operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61. Relational Operators and Expressions • 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. Relational Operators and Expressions • 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. Relational Operators and Expressions • 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. Relational Operators and Expressions • 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. Relational Operators and Expressions • 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. Equality and Inequality Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67. Equality and Inequality Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Evaluating Equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 70. Evaluating Equality 1. Same type, test for strict equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71. Evaluating Equality 1. Same type, test for strict equality 2. Not same type, convert and test for equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 72. Evaluating Equality 1. Same type, test for strict equality 2. 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. Evaluating Equality 1. Same type, test for strict equality 2. 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. Evaluating Equality 1. Same type, test for strict equality 2. 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. Evaluating Equality 1. Same type, test for strict equality 2. 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. Evaluating Equality 1. Same type, test for strict equality 2. 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. Evaluating Strict Equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 78. Evaluating Strict Equality 1. If operands are different types, not equal. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 79. Evaluating Strict Equality 1. 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. Evaluating Strict Equality 1. 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. Evaluating Strict Equality 1. 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. Evaluating Strict Equality 1. 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. Evaluating Strict Equality 1. 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. Evaluating Strict Equality 1. 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 7. If object references, equal if both reference same object. @ http://www.learnnowonline.com Learn More Copyright © by Application Developers Training Company
  • 85. Comparison Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 86. Comparison Operators • Compare relative values, return Boolean Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Logical Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89. Logical Operators and Expressions • Boolean algebra Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. String Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95. String Operators and Expressions • + is overloaded for string concatenation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. Special Operators and Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99. Special Operators and Expressions • Conditional operator ?: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100. Special Operators and Expressions • Conditional operator ?:  op1 ? op2 : op3 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Characteristics of Operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 113. Characteristics of Operators • Number and Type of Operands Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Other Expression Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126. Other Expression Types • Not all expressions rely on operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. Object Initializer Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. Property Access Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. Process to Evaluate Access Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 138. Process to Evaluate Access 1. Evaluate expression before . or [ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 139. Process to Evaluate Access 1. Evaluate expression before . or [  If null or undefined, throw error Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 140. Process to Evaluate Access 1. Evaluate expression before . or [  If null or undefined, throw error 2. If not an object or array, convert the value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 141. Process to Evaluate Access 1. Evaluate expression before . or [  If null or undefined, throw error 2. If not an object or array, convert the value 3. If uses the . notation with identifier Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 142. Process to Evaluate Access 1. Evaluate expression before . or [  If null or undefined, throw error 2. If not an object or array, convert the value 3. If uses the . notation with identifier  Retrieve value of property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 143. Process to Evaluate Access 1. Evaluate expression before . or [  If null or undefined, throw error 2. If not an object or array, convert the value 3. If uses the . notation with identifier  Retrieve value of property 4. 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. Invocation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Object Creation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. Evaluation Expressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 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. 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. 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. 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. 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

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. DEMO: next code in section\n
  28. DEMO: next code in section\n
  29. DEMO: rest of section\n
  30. DEMO: rest of section\n
  31. DEMO: rest of section\n
  32. DEMO: rest of section\n
  33. DEMO: rest of section\n
  34. DEMO: rest of section\n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. DEMO: next code in section\n
  41. DEMO: next code in section\n
  42. DEMO: rest of section\n
  43. DEMO: rest of section\n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. DEMO: rest of section\n
  79. DEMO: rest of section\n
  80. DEMO: rest of section\n
  81. DEMO: rest of section\n
  82. DEMO: rest of section\n
  83. DEMO: rest of section\n
  84. DEMO: rest of section\n
  85. DEMO: rest of section\n
  86. DEMO: rest of section\n
  87. \n
  88. \n
  89. \n
  90. DEMO: conditional operator code\n
  91. DEMO: conditional operator code\n
  92. DEMO: conditional operator code\n
  93. DEMO: conditional operator code\n
  94. DEMO: conditional operator code\n
  95. DEMO: conditional operator code\n
  96. DEMO: conditional operator code\n
  97. DEMO: conditional operator code\n
  98. DEMO: conditional operator code\n
  99. DEMO: conditional operator code\n
  100. DEMO: conditional operator code\n
  101. DEMO: conditional operator code\n
  102. DEMO: conditional operator code\n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. DEMO: rest of section, Function Expressions\n
  121. DEMO: rest of section, Function Expressions\n
  122. DEMO: rest of section, Function Expressions\n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. DEMO: rest of section\n
  153. DEMO: rest of section\n
  154. DEMO: rest of section\n
  155. DEMO: rest of section\n
  156. DEMO: rest of section\n
  157. DEMO: rest of section\n
  158. DEMO: rest of section\n
  159. DEMO: rest of section\n