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

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 aboutexpressions in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4.
    Objectives • Learn aboutexpressions 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 aboutexpressions 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 • Notall expressions require operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17.
    Operator-Based Expressions • Notall 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 • Notall 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 • Notall 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 • Notall 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 DecrementOperators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29.
    Increment and DecrementOperators • Add or subtract 1 to or from operand Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30.
    Increment and DecrementOperators • 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 DecrementOperators • 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 DecrementOperators • 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 DecrementOperators • 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 DecrementOperators • 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 andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36.
    Bitwise Operators andExpressions • Perform low-level bit manipulation of numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37.
    Bitwise Operators andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 InequalityOperators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67.
    Equality and InequalityOperators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68.
    Equality and InequalityOperators 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. Sametype, test for strict equality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71.
    Evaluating Equality 1. Sametype, 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. Sametype, 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. Sametype, 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. Sametype, 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. Sametype, 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. Sametype, 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 • Comparerelative values, return Boolean Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87.
    Comparison Operators • Comparerelative 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 andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89.
    Logical Operators andExpressions • Boolean algebra Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 90.
    Logical Operators andExpressions • Boolean algebra • Use of AND and OR operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91.
    Logical Operators andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95.
    String Operators andExpressions • + is overloaded for string concatenation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 96.
    String Operators andExpressions • + 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 andExpressions • + 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 andExpressions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99.
    Special Operators andExpressions • Conditional operator ?: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100.
    Special Operators andExpressions • Conditional operator ?:  op1 ? op2 : op3 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 101.
    Special Operators andExpressions • Conditional operator ?:  op1 ? op2 : op3 • Comma operator , Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 102.
    Special Operators andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 andExpressions • 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 EvaluateAccess Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 138.
    Process to EvaluateAccess 1. Evaluate expression before . or [ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 139.
    Process to EvaluateAccess 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 EvaluateAccess 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 EvaluateAccess 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 EvaluateAccess 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 EvaluateAccess 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 • Syntaxfor calling or executing a function or method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 146.
    Invocation Expressions • Syntaxfor calling or executing a function or method • General syntax Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 147.
    Invocation Expressions • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Syntaxfor 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 • Abilityto interpret strings of code on the fly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 167.
    Evaluation Expressions • Abilityto 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 • Abilityto 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! • Thisis 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! • Thisis 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! • Thisis 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! • Thisis 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! • Thisis 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

Editor's Notes