KEMBAR78
JavaScript: Values, Types and Variables | KEY
Values, Types, and Variables




       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 JavaScript types and comparisons




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Objectives
• Learn about JavaScript types and comparisons
• Understand both implicit and explicit type
  conversions




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Objectives
• Learn about JavaScript types and comparisons
• Understand both implicit and explicit type
  conversions
• See how to declare and use variables, as well as
  their scope




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introduction to Values, Types, and




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types
   Variables




           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types
   Variables
• JavaScript may seem limited and confining




           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types
   Variables
• JavaScript may seem limited and confining
   Weakly typed language, so variables are untyped




           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types
   Variables
• JavaScript may seem limited and confining
   Weakly typed language, so variables are untyped
   Object-oriented language




           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Introduction to Values, Types, and
• Handling data is the fundamental task of
  programming languages
   Values
   Types
   Variables
• JavaScript may seem limited and confining
   Weakly typed language, so variables are untyped
   Object-oriented language
• Type system is definitely one of the good parts
  of the language
           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
JavaScript Types




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
JavaScript Types
• Defines types you can use to work with values of
  different kinds




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
JavaScript Types
• Defines types you can use to work with values of
  different kinds
• Categorizing types




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
JavaScript Types
• Defines types you can use to work with values of
  different kinds
• Categorizing types
   Primitive and object types




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Types
• Defines types you can use to work with values of
  different kinds
• Categorizing types
   Primitive and object types
   With or without methods




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Types
• Defines types you can use to work with values of
  different kinds
• Categorizing types
   Primitive and object types
   With or without methods
   Mutable or immutable




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Primary Types in JavaScript




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Primary Types in JavaScript
  Type          Category                        Methods                 Mutability
 number          Primitive                        Yes                   Immutable
  string         Primitive                        Yes                   Immutable
 Boolean         Primitive                        Yes                   Immutable
   null          Primitive                        No                    Immutable
undefined        Primitive                        No                    Immutable
  object          Object                          Yes                    Mutable




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Primary Types in JavaScript
   Type          Category                        Methods                 Mutability
  number          Primitive                        Yes                   Immutable
   string         Primitive                        Yes                   Immutable
  Boolean         Primitive                        Yes                   Immutable
    null          Primitive                        No                    Immutable
 undefined        Primitive                        No                    Immutable
   object          Object                          Yes                    Mutable
• Bad part is that it will liberally convert values
  from one type to another



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Primary Types in JavaScript
   Type          Category                        Methods                 Mutability
  number          Primitive                        Yes                   Immutable
   string         Primitive                        Yes                   Immutable
  Boolean         Primitive                        Yes                   Immutable
    null          Primitive                        No                    Immutable
 undefined        Primitive                        No                    Immutable
   object          Object                          Yes                    Mutable
• Bad part is that it will liberally convert values
  from one type to another
• Special === operator


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




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
JavaScript Numbers
• All numbers are 64-bit floating-point values




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Numbers
• All numbers are 64-bit floating-point values
   IEEE 754 standard




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Numbers
• All numbers are 64-bit floating-point values
   IEEE 754 standard
   Numbers as large as ±1.7976931348623157x10308 to
    as small as ±5x10-324




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Numbers
• All numbers are 64-bit floating-point values
   IEEE 754 standard
   Numbers as large as ±1.7976931348623157x10308 to
    as small as ±5x10-324
   Integers between -9,007,199,254,740,992 (-253) and
    9,007,199,254,740,992 (253), inclusive




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Numbers
• All numbers are 64-bit floating-point values
   IEEE 754 standard
   Numbers as large as ±1.7976931348623157x10308 to
    as small as ±5x10-324
   Integers between -9,007,199,254,740,992 (-253) and
    9,007,199,254,740,992 (253), inclusive
   If you work with numbers outside integer range, you’ll
    lose precision




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




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
   5, 100, 123456789, 0, -100




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4
• ECMAScript doesn’t support octal (base 8)




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4
• ECMAScript doesn’t support octal (base 8)
    Some JavaScript implementations support




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4
• ECMAScript doesn’t support octal (base 8)
    Some JavaScript implementations support
    Number starts with a leading zero, followed by digits from 0 to 7




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4
• ECMAScript doesn’t support octal (base 8)
    Some JavaScript implementations support
    Number starts with a leading zero, followed by digits from 0 to 7
    Code won’t be portable




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Integer Literals
• Represent either as base 10 or hexadecimal
• All these are valid base 10 values
    5, 100, 123456789, 0, -100
• Valid hex values
    0x1a5f, 0X1A5F, 0x10cd4
• ECMAScript doesn’t support octal (base 8)
      Some JavaScript implementations support
      Number starts with a leading zero, followed by digits from 0 to 7
      Code won’t be portable
      ECMAScript 5/Strict forbids



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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.
   Omit either integral or fractional part




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.
   Omit either integral or fractional part
• Exponential numbers




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.
   Omit either integral or fractional part
• Exponential numbers
   1.23e12             // 1.23 x 1012




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.
   Omit either integral or fractional part
• Exponential numbers
   1.23e12              // 1.23 x 1012
   1.23e-12                    // 1.23 x 10-12




           Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Real Number Literals
• Express either as real number or exponential
• Real numbers
   1.0, 1.349201942, .3333333333,
    125959403.39201488, 56.
   Omit either integral or fractional part
• Exponential numbers
   1.23e12      // 1.23 x 1012
   1.23e-12            // 1.23 x 10-12
   5.90849203e5        // 5.90849203 x 105


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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Arithmetic in JavaScript
• Expected set of arithmetic operators




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Arithmetic in JavaScript
• Expected set of arithmetic operators
   Including + (addition), - (subtraction),
    * (multiplication), / (division), and % (modulo)




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Arithmetic in JavaScript
• Expected set of arithmetic operators
   Including + (addition), - (subtraction),
    * (multiplication), / (division), and % (modulo)
   No integral division




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Arithmetic in JavaScript
• Expected set of arithmetic operators
   Including + (addition), - (subtraction),
    * (multiplication), / (division), and % (modulo)
   No integral division
• Math object for other operations




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
   From zero to as many as will fit in memory




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
   From zero to as many as will fit in memory
   Consist of letters, numbers, punctuation, and spaces




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
   From zero to as many as will fit in memory
   Consist of letters, numbers, punctuation, and spaces
   Zero-based indexing




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
     From zero to as many as will fit in memory
     Consist of letters, numbers, punctuation, and spaces
     Zero-based indexing
     Empty string (“”) has length of zero




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
     From zero to as many as will fit in memory
     Consist of letters, numbers, punctuation, and spaces
     Zero-based indexing
     Empty string (“”) has length of zero
     No special type to represent a single character




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
     From zero to as many as will fit in memory
     Consist of letters, numbers, punctuation, and spaces
     Zero-based indexing
     Empty string (“”) has length of zero
     No special type to represent a single character
• Delimit with single ' or double " quotes



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
     From zero to as many as will fit in memory
     Consist of letters, numbers, punctuation, and spaces
     Zero-based indexing
     Empty string (“”) has length of zero
     No special type to represent a single character
• Delimit with single ' or double " quotes
   Can’t mix to delimit string


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
JavaScript Strings
• Ordered, immutable sequence of 16-bit Unicode
  characters
     From zero to as many as will fit in memory
     Consist of letters, numbers, punctuation, and spaces
     Zero-based indexing
     Empty string (“”) has length of zero
     No special type to represent a single character
• Delimit with single ' or double " quotes
   Can’t mix to delimit string
   Can embed quote not used to delimit string

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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
String Delimiters
• Either string is valid




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
String Delimiters
• Either string is valid
    "'Don't use that food to feed the dog,'
     she said. 'It's been recalled by the
     manufacturer.'"




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
String Delimiters
• Either string is valid
    "'Don't use that food to feed                                     the dog,'
     she said. 'It's been recalled                                     by the
     manufacturer.'"
    '"Don"t use that food to feed                                     the dog,"
     she said. "It"s been recalled                                     by the
     manufacturer."'




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
String Delimiters
• Either string is valid
    "'Don't use that food to feed                                     the dog,'
     she said. 'It's been recalled                                     by the
     manufacturer.'"
    '"Don"t use that food to feed                                     the dog,"
     she said. "It"s been recalled                                     by the
     manufacturer."'
• Not valid




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
String Delimiters
• Either string is valid
    "'Don't use that food to feed                                     the dog,'
     she said. 'It's been recalled                                     by the
     manufacturer.'"
    '"Don"t use that food to feed                                     the dog,"
     she said. "It"s been recalled                                     by the
     manufacturer."'
• Not valid
    '"Don't use that food to feed the dog,"
     she said. "It has been recalled by the
     manufacturer."'


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




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals
    ""                                // an empty string




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals
    ""                                // an empty string
    ''                                // another empty string




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals
    ""                                // an empty string
    ''                                // another empty string
    "Don Kiely"




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals
      ""                              // an empty string
      ''                              // another empty string
      "Don Kiely"
      '1.414'                         // a number represented
                                               as a string




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
String Literals
• All the following are valid string literals
      ""                              // an empty string
      ''                              // another empty string
      "Don Kiely"
      '1.414'       // a number represented
                             as a string
    "My password is 'beetle$%^Bailey392'"




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Line Breaks in String Literals




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line
   ECMAScript 5 allows break with  at end of line




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line
   ECMAScript 5 allows break with  at end of line
• Problem in ECMAScript 3 but fine in 5:




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line
   ECMAScript 5 allows break with  at end of line
• Problem in ECMAScript 3 but fine in 5:
  "Four score and seven years ago our fathers 
  brought forth on this continent, a new nation, 
  conceived in Liberty, and dedicated to the 
  proposition that all men are created equal."




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line
   ECMAScript 5 allows break with  at end of line
• Problem in ECMAScript 3 but fine in 5:
  "Four score and seven years ago our fathers 
  brought forth on this continent, a new nation, 
  conceived in Liberty, and dedicated to the 
  proposition that all men are created equal."

• Following is invalid…see the difference?




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Line Breaks in String Literals
• ECMAScript 3 requires string literal on one line
   ECMAScript 5 allows break with  at end of line
• Problem in ECMAScript 3 but fine in 5:
  "Four score and seven years ago our fathers 
  brought forth on this continent, a new nation, 
  conceived in Liberty, and dedicated to the 
  proposition that all men are created equal."

• Following is invalid…see the difference?
  "Four score and seven years ago our fathers 
  brought forth on this continent, a new nation, 
  conceived in Liberty, and dedicated to the 
  proposition that all men are created equal."
            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Escape Sequences in String Literals




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Escape Sequences in String Literals
• Include characters that have special meaning by
  using an escape sequence




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Escape Sequences in String Literals
• Include characters that have special meaning by
  using an escape sequence
   Backslash  identifies the special character




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Escape Sequences in String Literals
• Include characters that have special meaning by
  using an escape sequence
   Backslash  identifies the special character
   '"Don't use that food to feed the dog,"
    she said. "It's been recalled by the
    manufacturer."‘




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
JavaScript Escape Sequences
Escape Sequence                                     Description
      '          Single quote or apostrophe
      "          Double quote
                Backslash
      0          Nul character (that’s a backslash-zero)
      b          Backspace
      f          Form feed
      n          Newline
      r          Carriage return
      t          Horizontal tab
      v          Vertical tab
     xXX         The Latin-1 character specified by the two
    uXXXX        hexadecimal digits XX between 00 and ff. For example,
                  The Unicode character specified by the four
                  the copyrightdigits dddd. For example, the π symbol is
                  hexadecimal symbol is xa9.
             Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
JavaScript Boolean Values




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)
     "" (empty string)




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)
     "" (empty string)
     NaN




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)
     "" (empty string)
     NaN
     null




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)
     "" (empty string)
     NaN
     null
     undefined



           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
JavaScript Boolean Values
• Represents true or false
   Usually the result of some logical comparison
• JavaScript can convert any value to a Boolean
   These are all false
     0 (zero)
     -0 (negative zero)
     "" (empty string)
     NaN
     null
     undefined
   All other values are true

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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false
• These are generally equivalent




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false
• These are generally equivalent
    if (result !== 0)




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false
• These are generally equivalent
    if (result !== 0)
    if (result)




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false
• These are generally equivalent
    if (result !== 0)
    if (result)
• But be careful!



              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Truthy and Falsy
• Any value that converts to true is truthy
• Any value that converts to false is falsy
• When JavaScript expects a Boolean value
    Truthy value works like true
    Falsy value works like false
• These are generally equivalent
    if (result !== 0)
    if (result)
• But be careful!
    The result variable could hold other truthy or falsy values


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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"
   valueOf() returns true of false




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"
   valueOf() returns true of false
• Logical operators




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"
   valueOf() returns true of false
• Logical operators
   && AND




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"
   valueOf() returns true of false
• Logical operators
   && AND
   || OR




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Boolean Methods and Logical
• Boolean values have two methods
   toString() returns "true" or "false"
   valueOf() returns true of false
• Logical operators
   && AND
   || OR
   ! NOT




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Special Values: null and undefined




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Special Values: null and undefined
• null




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type
    Absence of a value




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type
    Absence of a value
• undefined




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type
    Absence of a value
• undefined
    Also means absence of value, but in a deeper way




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type
    Absence of a value
• undefined
    Also means absence of value, but in a deeper way
    Predefined global variable




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Special Values: null and undefined
• null
    Language keyword
    An object, but considered a separate type
    Absence of a value
• undefined
    Also means absence of value, but in a deeper way
    Predefined global variable
    Type is undefined (literally, that’s its type)




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




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value
   Function parameter that the calling code doesn’t
    provide a value for




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value
   Function parameter that the calling code doesn’t
    provide a value for
   Property that doesn’t exist on an object




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value
   Function parameter that the calling code doesn’t
    provide a value for
   Property that doesn’t exist on an object
   Array element that doesn’t exist




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value
   Function parameter that the calling code doesn’t
    provide a value for
   Property that doesn’t exist on an object
   Array element that doesn’t exist
   Function that doesn’t return a value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
undefined
• JavaScript uses in a few different ways
   Variable that has been declared but not yet assigned
    a value
   Function parameter that the calling code doesn’t
    provide a value for
   Property that doesn’t exist on an object
   Array element that doesn’t exist
   Function that doesn’t return a value
• undefined is read/write in ECMAScript 3, read-
  only in ECMAScript 5

           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Use null or undefined?




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined
• Best advice




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined
• Best advice
    Use undefined to represent system-level, unexpected, or
     erroneous absence of value




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined
• Best advice
    Use undefined to represent system-level, unexpected, or
     erroneous absence of value
    Use null to represent a program-level normal, or expected
     absence of value




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined
• Best advice
    Use undefined to represent system-level, unexpected, or
     erroneous absence of value
    Use null to represent a program-level normal, or expected
     absence of value
• In other words, use null when you need to express
  missing value


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Use null or undefined?
• Both mean absence of value
    Can often use interchangeably
    In fact, null == undefined
    But null !== undefined
• Best advice
    Use undefined to represent system-level, unexpected, or
     erroneous absence of value
    Use null to represent a program-level normal, or expected
     absence of value
• In other words, use null when you need to express
  missing value
    Let JavaScript manage use of undefined

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




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Type Comparisons
• JavaScript compares primitive values and object
  values differently




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Type Comparisons
• JavaScript compares primitive values and object
  values differently
   Primitive values by value




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Comparisons
• JavaScript compares primitive values and object
  values differently
   Primitive values by value
   Object values by reference




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




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Object Comparisons
• JavaScript compares objects by reference




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Object Comparisons
• JavaScript compares objects by reference
   Equal only if the two variables hold a reference to the
    same object in memory




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Object Comparisons
• JavaScript compares objects by reference
   Equal only if the two variables hold a reference to the
    same object in memory
   If hold a reference to two different objects, even if
    objects are the exact same, they are not equal




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want
• Automatic type conversions




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want
• Automatic type conversions
   Convert to truthy or falsy when expects Boolean




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want
• Automatic type conversions
   Convert to truthy or falsy when expects Boolean
   Converts anything to a string when expects string




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want
• Automatic type conversions
   Convert to truthy or falsy when expects Boolean
   Converts anything to a string when expects string
   Tries to convert to a number when expects number




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Type Conversions
• Feature that makes JavaScript easy and hard
   Does everything it can to implicitly convert values to
    make useable in a statement
   Doesn’t always do what you want
• Automatic type conversions
   Convert to truthy or falsy when expects Boolean
   Converts anything to a string when expects string
   Tries to convert to a number when expects number
• Also supports explicit type conversions


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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code
• Various ways




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code
• Various ways
    Wrapper objects




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code
• Various ways
    Wrapper objects
    Type methods




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code
• Various ways
    Wrapper objects
    Type methods
    Global functions




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Explicit Type Conversions
• You can do it yourself explicitly
    Use when implicit conversions don’t work for you
    Or you want cleaner and clearer code
• Various ways
      Wrapper objects
      Type methods
      Global functions
      …among others




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Formatting Methods and Parsing
Functions




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Formatting Methods and Parsing
Functions
• Don’t have much control with other conversion
  techniques




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Formatting Methods and Parsing
Functions
• Don’t have much control with other conversion
  techniques
   Get a reasonable value in the type you want




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Formatting Methods and Parsing
Functions
• Don’t have much control with other conversion
  techniques
   Get a reasonable value in the type you want
• JavaScript has specialized methods and functions
  that give you control




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects
• Number, String, Boolean, and Object wrapper
  objects




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects
• Number, String, Boolean, and Object wrapper
  objects
   Provide properties and methods for corresponding
    types




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects
• Number, String, Boolean, and Object wrapper
  objects
   Provide properties and methods for corresponding
    types
   Creates a String object and uses length property




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects
• Number, String, Boolean, and Object wrapper
  objects
   Provide properties and methods for corresponding
    types
   Creates a String object and uses length property
     o   "AppDev".length




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Conversions Using Wrapper Objects
• Number, String, Boolean, and Object wrapper
  objects
   Provide properties and methods for corresponding
    types
   Creates a String object and uses length property
     o   "AppDev".length

• Can use these functions for explicit conversion




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




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Number Formatting Methods
• Give more control than toString()




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Number Formatting Methods
• Give more control than toString()
   toFixed()




           Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Number Formatting Methods
• Give more control than toString()
   toFixed()
   toPrecision()




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Number Formatting Methods
• Give more control than toString()
   toFixed()
   toPrecision()
   toExponential()




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Number Formatting Methods
• Give more control than toString()
   toFixed()
   toPrecision()
   toExponential()
• All three round number or pad with zeros as
  necessary




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Using Variables
• Way to temporarily store bits of data




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using Variables
• Way to temporarily store bits of data
• Necessity in almost every language




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using Variables
• Way to temporarily store bits of data
• Necessity in almost every language
• JavaScript variables are a bit different




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;
   var lastName;




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
    var count;
    var minMsgID;
    var lastName;
• Undefined until initialized




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;
   var lastName;
• Undefined until initialized
• Can declare and initialize in one statement




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;
   var lastName;
• Undefined until initialized
• Can declare and initialize in one statement
   var count = 0;



           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;
   var lastName;
• Undefined until initialized
• Can declare and initialize in one statement
   var count = 0;
   var minMsgID = 32629;


           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Not required, but you should do it
• Untyped, so simple: use var with identifier
   var count;
   var minMsgID;
   var lastName;
• Undefined until initialized
• Can declare and initialize in one statement
   var count = 0;
   var minMsgID = 32629;
   var lastName = "Kiely";

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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement
   var count = 0, minMsgID = 32629, lastName = "Kiely";




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement
   var count = 0, minMsgID = 32629, lastName = "Kiely";

• Break onto multiple lines




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement
   var count = 0, minMsgID = 32629, lastName = "Kiely";

• Break onto multiple lines
   var count = 0,
          minMsgID = 32629,
          lastName = "Kiely";




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement
    var count = 0, minMsgID = 32629, lastName = "Kiely";

• Break onto multiple lines
    var count = 0,
           minMsgID = 32629,
           lastName = "Kiely";
• Declare and initialize within loops




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Variable Declaration
• Multiple variables in single var statement
    var count = 0, minMsgID = 32629, lastName = "Kiely";

• Break onto multiple lines
    var count = 0,
           minMsgID = 32629,
           lastName = "Kiely";
• Declare and initialize within loops
    for (var i = 2; i <= 36; i++)
           console.log("Base " + i + ": " +
                num.toString(i));


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Variable Cautions and Gotchas




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Variable Cautions and Gotchas
• Variable can hold any type during execution




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Cautions and Gotchas
• Variable can hold any type during execution
   var count = 0;
          <program code>
    count = "Don";
          <more program code>
    count = false
          <yet more code>
    count = "The Duke of Windsor";




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Cautions and Gotchas
• Variable can hold any type during execution
    var count = 0;
           <program code>
     count = "Don";
           <more program code>
     count = false
           <yet more code>
     count = "The Duke of Windsor";
• Be careful splitting across multiple lines!



           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Cautions and Gotchas
• Variable can hold any type during execution
    var count = 0;
           <program code>
     count = "Don";
           <more program code>
     count = false
           <yet more code>
     count = "The Duke of Windsor";
• Be careful splitting across multiple lines!
    var count = 0
           minMsgID = 32629,
           lastName = "Kiely";

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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Variable Scope
• Scope is section of code where variable is
  defined and accessible




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Scope
• Scope is section of code where variable is
  defined and accessible
• Two scopes in JavaScript




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Scope
• Scope is section of code where variable is
  defined and accessible
• Two scopes in JavaScript
   Global




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Variable Scope
• Scope is section of code where variable is
  defined and accessible
• Two scopes in JavaScript
   Global
   Local




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Variable Scope
• Scope is section of code where variable is
  defined and accessible
• Two scopes in JavaScript
   Global
   Local
• Local variable has function scope in JavaScript




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




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Variable Hoisting
• Function scope has an important implication




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Variable Hoisting
• Function scope has an important implication
• All local variables declared within a function




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Variable Hoisting
• Function scope has an important implication
• All local variables declared within a function
    Visible throughout the body of the function




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Variable Hoisting
• Function scope has an important implication
• All local variables declared within a function
    Visible throughout the body of the function
• Side effect: all local variables are visible even
  before they are declared




            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

JavaScript: Values, Types and Variables

  • 1.
    Values, Types, andVariables 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 aboutJavaScript types and comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4.
    Objectives • Learn aboutJavaScript types and comparisons • Understand both implicit and explicit type conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 5.
    Objectives • Learn aboutJavaScript types and comparisons • Understand both implicit and explicit type conversions • See how to declare and use variables, as well as their scope Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 6.
    Introduction to Values,Types, and Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 8.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 9.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 10.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types  Variables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 11.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types  Variables • JavaScript may seem limited and confining Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 12.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types  Variables • JavaScript may seem limited and confining  Weakly typed language, so variables are untyped Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 13.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types  Variables • JavaScript may seem limited and confining  Weakly typed language, so variables are untyped  Object-oriented language Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 14.
    Introduction to Values,Types, and • Handling data is the fundamental task of programming languages  Values  Types  Variables • JavaScript may seem limited and confining  Weakly typed language, so variables are untyped  Object-oriented language • Type system is definitely one of the good parts of the language Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 15.
    JavaScript Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16.
    JavaScript Types • Definestypes you can use to work with values of different kinds Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17.
    JavaScript Types • Definestypes you can use to work with values of different kinds • Categorizing types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 18.
    JavaScript Types • Definestypes you can use to work with values of different kinds • Categorizing types  Primitive and object types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 19.
    JavaScript Types • Definestypes you can use to work with values of different kinds • Categorizing types  Primitive and object types  With or without methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 20.
    JavaScript Types • Definestypes you can use to work with values of different kinds • Categorizing types  Primitive and object types  With or without methods  Mutable or immutable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 21.
    Primary Types inJavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22.
    Primary Types inJavaScript Type Category Methods Mutability number Primitive Yes Immutable string Primitive Yes Immutable Boolean Primitive Yes Immutable null Primitive No Immutable undefined Primitive No Immutable object Object Yes Mutable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23.
    Primary Types inJavaScript Type Category Methods Mutability number Primitive Yes Immutable string Primitive Yes Immutable Boolean Primitive Yes Immutable null Primitive No Immutable undefined Primitive No Immutable object Object Yes Mutable • Bad part is that it will liberally convert values from one type to another Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 24.
    Primary Types inJavaScript Type Category Methods Mutability number Primitive Yes Immutable string Primitive Yes Immutable Boolean Primitive Yes Immutable null Primitive No Immutable undefined Primitive No Immutable object Object Yes Mutable • Bad part is that it will liberally convert values from one type to another • Special === operator Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 25.
    JavaScript Numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26.
    JavaScript Numbers • Allnumbers are 64-bit floating-point values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27.
    JavaScript Numbers • Allnumbers are 64-bit floating-point values  IEEE 754 standard Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 28.
    JavaScript Numbers • Allnumbers are 64-bit floating-point values  IEEE 754 standard  Numbers as large as ±1.7976931348623157x10308 to as small as ±5x10-324 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29.
    JavaScript Numbers • Allnumbers are 64-bit floating-point values  IEEE 754 standard  Numbers as large as ±1.7976931348623157x10308 to as small as ±5x10-324  Integers between -9,007,199,254,740,992 (-253) and 9,007,199,254,740,992 (253), inclusive Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30.
    JavaScript Numbers • Allnumbers are 64-bit floating-point values  IEEE 754 standard  Numbers as large as ±1.7976931348623157x10308 to as small as ±5x10-324  Integers between -9,007,199,254,740,992 (-253) and 9,007,199,254,740,992 (253), inclusive  If you work with numbers outside integer range, you’ll lose precision Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 31.
    Integer Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32.
    Integer Literals • Representeither as base 10 or hexadecimal Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 34.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 35.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 • ECMAScript doesn’t support octal (base 8) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 38.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 • ECMAScript doesn’t support octal (base 8)  Some JavaScript implementations support Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 39.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 • ECMAScript doesn’t support octal (base 8)  Some JavaScript implementations support  Number starts with a leading zero, followed by digits from 0 to 7 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 40.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 • ECMAScript doesn’t support octal (base 8)  Some JavaScript implementations support  Number starts with a leading zero, followed by digits from 0 to 7  Code won’t be portable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 41.
    Integer Literals • Representeither as base 10 or hexadecimal • All these are valid base 10 values  5, 100, 123456789, 0, -100 • Valid hex values  0x1a5f, 0X1A5F, 0x10cd4 • ECMAScript doesn’t support octal (base 8)  Some JavaScript implementations support  Number starts with a leading zero, followed by digits from 0 to 7  Code won’t be portable  ECMAScript 5/Strict forbids Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42.
    Real Number Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 43.
    Real Number Literals •Express either as real number or exponential Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 44.
    Real Number Literals •Express either as real number or exponential • Real numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 46.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56.  Omit either integral or fractional part Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 47.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56.  Omit either integral or fractional part • Exponential numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56.  Omit either integral or fractional part • Exponential numbers  1.23e12 // 1.23 x 1012 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56.  Omit either integral or fractional part • Exponential numbers  1.23e12 // 1.23 x 1012  1.23e-12 // 1.23 x 10-12 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 50.
    Real Number Literals •Express either as real number or exponential • Real numbers  1.0, 1.349201942, .3333333333, 125959403.39201488, 56.  Omit either integral or fractional part • Exponential numbers  1.23e12 // 1.23 x 1012  1.23e-12 // 1.23 x 10-12  5.90849203e5 // 5.90849203 x 105 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 51.
    Arithmetic in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 52.
    Arithmetic in JavaScript •Expected set of arithmetic operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 53.
    Arithmetic in JavaScript •Expected set of arithmetic operators  Including + (addition), - (subtraction), * (multiplication), / (division), and % (modulo) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 54.
    Arithmetic in JavaScript •Expected set of arithmetic operators  Including + (addition), - (subtraction), * (multiplication), / (division), and % (modulo)  No integral division Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 55.
    Arithmetic in JavaScript •Expected set of arithmetic operators  Including + (addition), - (subtraction), * (multiplication), / (division), and % (modulo)  No integral division • Math object for other operations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56.
    JavaScript Strings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 57.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 58.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 59.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing  Empty string (“”) has length of zero Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 62.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing  Empty string (“”) has length of zero  No special type to represent a single character Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 63.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing  Empty string (“”) has length of zero  No special type to represent a single character • Delimit with single ' or double " quotes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 64.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing  Empty string (“”) has length of zero  No special type to represent a single character • Delimit with single ' or double " quotes  Can’t mix to delimit string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 65.
    JavaScript Strings • Ordered,immutable sequence of 16-bit Unicode characters  From zero to as many as will fit in memory  Consist of letters, numbers, punctuation, and spaces  Zero-based indexing  Empty string (“”) has length of zero  No special type to represent a single character • Delimit with single ' or double " quotes  Can’t mix to delimit string  Can embed quote not used to delimit string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 66.
    String Delimiters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67.
    String Delimiters • Eitherstring is valid Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68.
    String Delimiters • Eitherstring is valid  "'Don't use that food to feed the dog,' she said. 'It's been recalled by the manufacturer.'" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 69.
    String Delimiters • Eitherstring is valid  "'Don't use that food to feed the dog,' she said. 'It's been recalled by the manufacturer.'"  '"Don"t use that food to feed the dog," she said. "It"s been recalled by the manufacturer."' Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 70.
    String Delimiters • Eitherstring is valid  "'Don't use that food to feed the dog,' she said. 'It's been recalled by the manufacturer.'"  '"Don"t use that food to feed the dog," she said. "It"s been recalled by the manufacturer."' • Not valid Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71.
    String Delimiters • Eitherstring is valid  "'Don't use that food to feed the dog,' she said. 'It's been recalled by the manufacturer.'"  '"Don"t use that food to feed the dog," she said. "It"s been recalled by the manufacturer."' • Not valid  '"Don't use that food to feed the dog," she said. "It has been recalled by the manufacturer."' Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 72.
    String Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 73.
    String Literals • Allthe following are valid string literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 74.
    String Literals • Allthe following are valid string literals  "" // an empty string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 75.
    String Literals • Allthe following are valid string literals  "" // an empty string  '' // another empty string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 76.
    String Literals • Allthe following are valid string literals  "" // an empty string  '' // another empty string  "Don Kiely" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 77.
    String Literals • Allthe following are valid string literals  "" // an empty string  '' // another empty string  "Don Kiely"  '1.414' // a number represented as a string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 78.
    String Literals • Allthe following are valid string literals  "" // an empty string  '' // another empty string  "Don Kiely"  '1.414' // a number represented as a string  "My password is 'beetle$%^Bailey392'" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 79.
    Line Breaks inString Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 80.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 81.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line  ECMAScript 5 allows break with at end of line Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 82.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line  ECMAScript 5 allows break with at end of line • Problem in ECMAScript 3 but fine in 5: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 83.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line  ECMAScript 5 allows break with at end of line • Problem in ECMAScript 3 but fine in 5: "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 84.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line  ECMAScript 5 allows break with at end of line • Problem in ECMAScript 3 but fine in 5: "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." • Following is invalid…see the difference? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 85.
    Line Breaks inString Literals • ECMAScript 3 requires string literal on one line  ECMAScript 5 allows break with at end of line • Problem in ECMAScript 3 but fine in 5: "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." • Following is invalid…see the difference? "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 86.
    Escape Sequences inString Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87.
    Escape Sequences inString Literals • Include characters that have special meaning by using an escape sequence Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 88.
    Escape Sequences inString Literals • Include characters that have special meaning by using an escape sequence  Backslash identifies the special character Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89.
    Escape Sequences inString Literals • Include characters that have special meaning by using an escape sequence  Backslash identifies the special character  '"Don't use that food to feed the dog," she said. "It's been recalled by the manufacturer."‘ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 90.
    JavaScript Escape Sequences Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91.
    JavaScript Escape Sequences EscapeSequence Description ' Single quote or apostrophe " Double quote Backslash 0 Nul character (that’s a backslash-zero) b Backspace f Form feed n Newline r Carriage return t Horizontal tab v Vertical tab xXX The Latin-1 character specified by the two uXXXX hexadecimal digits XX between 00 and ff. For example, The Unicode character specified by the four the copyrightdigits dddd. For example, the π symbol is hexadecimal symbol is xa9. Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 92.
    JavaScript Boolean Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 93.
    JavaScript Boolean Values •Represents true or false Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 94.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 96.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 97.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 98.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) "" (empty string) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) "" (empty string) NaN Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 101.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) "" (empty string) NaN null Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 102.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) "" (empty string) NaN null undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 103.
    JavaScript Boolean Values •Represents true or false  Usually the result of some logical comparison • JavaScript can convert any value to a Boolean  These are all false 0 (zero) -0 (negative zero) "" (empty string) NaN null undefined  All other values are true Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 104.
    Truthy and Falsy Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 105.
    Truthy and Falsy •Any value that converts to true is truthy Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 106.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 107.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 108.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 109.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 110.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false • These are generally equivalent Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 111.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false • These are generally equivalent  if (result !== 0) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 112.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false • These are generally equivalent  if (result !== 0)  if (result) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 113.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false • These are generally equivalent  if (result !== 0)  if (result) • But be careful! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 114.
    Truthy and Falsy •Any value that converts to true is truthy • Any value that converts to false is falsy • When JavaScript expects a Boolean value  Truthy value works like true  Falsy value works like false • These are generally equivalent  if (result !== 0)  if (result) • But be careful!  The result variable could hold other truthy or falsy values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 115.
    Boolean Methods andLogical Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 116.
    Boolean Methods andLogical • Boolean values have two methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 117.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false" Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 118.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false"  valueOf() returns true of false Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 119.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false"  valueOf() returns true of false • Logical operators Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 120.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false"  valueOf() returns true of false • Logical operators  && AND Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 121.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false"  valueOf() returns true of false • Logical operators  && AND  || OR Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 122.
    Boolean Methods andLogical • Boolean values have two methods  toString() returns "true" or "false"  valueOf() returns true of false • Logical operators  && AND  || OR  ! NOT Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 123.
    Special Values: nulland undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 124.
    Special Values: nulland undefined • null Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 125.
    Special Values: nulland undefined • null  Language keyword Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 127.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type  Absence of a value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 128.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type  Absence of a value • undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 129.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type  Absence of a value • undefined  Also means absence of value, but in a deeper way Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 130.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type  Absence of a value • undefined  Also means absence of value, but in a deeper way  Predefined global variable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 131.
    Special Values: nulland undefined • null  Language keyword  An object, but considered a separate type  Absence of a value • undefined  Also means absence of value, but in a deeper way  Predefined global variable  Type is undefined (literally, that’s its type) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 132.
    undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 133.
    undefined • JavaScript usesin a few different ways Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 134.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 135.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value  Function parameter that the calling code doesn’t provide a value for Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 136.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value  Function parameter that the calling code doesn’t provide a value for  Property that doesn’t exist on an object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 137.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value  Function parameter that the calling code doesn’t provide a value for  Property that doesn’t exist on an object  Array element that doesn’t exist Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 138.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value  Function parameter that the calling code doesn’t provide a value for  Property that doesn’t exist on an object  Array element that doesn’t exist  Function that doesn’t return a value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 139.
    undefined • JavaScript usesin a few different ways  Variable that has been declared but not yet assigned a value  Function parameter that the calling code doesn’t provide a value for  Property that doesn’t exist on an object  Array element that doesn’t exist  Function that doesn’t return a value • undefined is read/write in ECMAScript 3, read- only in ECMAScript 5 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 140.
    Use null orundefined? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 141.
    Use null orundefined? • Both mean absence of value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 142.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 143.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 144.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 145.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined • Best advice Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 146.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined • Best advice  Use undefined to represent system-level, unexpected, or erroneous absence of value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 147.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined • Best advice  Use undefined to represent system-level, unexpected, or erroneous absence of value  Use null to represent a program-level normal, or expected absence of value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 148.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined • Best advice  Use undefined to represent system-level, unexpected, or erroneous absence of value  Use null to represent a program-level normal, or expected absence of value • In other words, use null when you need to express missing value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 149.
    Use null orundefined? • Both mean absence of value  Can often use interchangeably  In fact, null == undefined  But null !== undefined • Best advice  Use undefined to represent system-level, unexpected, or erroneous absence of value  Use null to represent a program-level normal, or expected absence of value • In other words, use null when you need to express missing value  Let JavaScript manage use of undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 150.
    Type Comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 151.
    Type Comparisons • JavaScriptcompares primitive values and object values differently Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 152.
    Type Comparisons • JavaScriptcompares primitive values and object values differently  Primitive values by value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 153.
    Type Comparisons • JavaScriptcompares primitive values and object values differently  Primitive values by value  Object values by reference Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 154.
    Object Comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 155.
    Object Comparisons • JavaScriptcompares objects by reference Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 156.
    Object Comparisons • JavaScriptcompares objects by reference  Equal only if the two variables hold a reference to the same object in memory Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 157.
    Object Comparisons • JavaScriptcompares objects by reference  Equal only if the two variables hold a reference to the same object in memory  If hold a reference to two different objects, even if objects are the exact same, they are not equal Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 158.
    Type Conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 159.
    Type Conversions • Featurethat makes JavaScript easy and hard Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 160.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 161.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 162.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want • Automatic type conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 163.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want • Automatic type conversions  Convert to truthy or falsy when expects Boolean Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 164.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want • Automatic type conversions  Convert to truthy or falsy when expects Boolean  Converts anything to a string when expects string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 165.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want • Automatic type conversions  Convert to truthy or falsy when expects Boolean  Converts anything to a string when expects string  Tries to convert to a number when expects number Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 166.
    Type Conversions • Featurethat makes JavaScript easy and hard  Does everything it can to implicitly convert values to make useable in a statement  Doesn’t always do what you want • Automatic type conversions  Convert to truthy or falsy when expects Boolean  Converts anything to a string when expects string  Tries to convert to a number when expects number • Also supports explicit type conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 167.
    Explicit Type Conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 168.
    Explicit Type Conversions •You can do it yourself explicitly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 169.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 170.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 171.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code • Various ways Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 172.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code • Various ways  Wrapper objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 173.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code • Various ways  Wrapper objects  Type methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 174.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code • Various ways  Wrapper objects  Type methods  Global functions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 175.
    Explicit Type Conversions •You can do it yourself explicitly  Use when implicit conversions don’t work for you  Or you want cleaner and clearer code • Various ways  Wrapper objects  Type methods  Global functions  …among others Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 176.
    Formatting Methods andParsing Functions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 177.
    Formatting Methods andParsing Functions • Don’t have much control with other conversion techniques Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 178.
    Formatting Methods andParsing Functions • Don’t have much control with other conversion techniques  Get a reasonable value in the type you want Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 179.
    Formatting Methods andParsing Functions • Don’t have much control with other conversion techniques  Get a reasonable value in the type you want • JavaScript has specialized methods and functions that give you control Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 180.
    Conversions Using WrapperObjects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 181.
    Conversions Using WrapperObjects • Number, String, Boolean, and Object wrapper objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 182.
    Conversions Using WrapperObjects • Number, String, Boolean, and Object wrapper objects  Provide properties and methods for corresponding types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 183.
    Conversions Using WrapperObjects • Number, String, Boolean, and Object wrapper objects  Provide properties and methods for corresponding types  Creates a String object and uses length property Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 184.
    Conversions Using WrapperObjects • Number, String, Boolean, and Object wrapper objects  Provide properties and methods for corresponding types  Creates a String object and uses length property o "AppDev".length Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 185.
    Conversions Using WrapperObjects • Number, String, Boolean, and Object wrapper objects  Provide properties and methods for corresponding types  Creates a String object and uses length property o "AppDev".length • Can use these functions for explicit conversion Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 186.
    Number Formatting Methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 187.
    Number Formatting Methods •Give more control than toString() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 188.
    Number Formatting Methods •Give more control than toString()  toFixed() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 189.
    Number Formatting Methods •Give more control than toString()  toFixed()  toPrecision() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 190.
    Number Formatting Methods •Give more control than toString()  toFixed()  toPrecision()  toExponential() Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 191.
    Number Formatting Methods •Give more control than toString()  toFixed()  toPrecision()  toExponential() • All three round number or pad with zeros as necessary Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 192.
    Using Variables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 193.
    Using Variables • Wayto temporarily store bits of data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 194.
    Using Variables • Wayto temporarily store bits of data • Necessity in almost every language Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 195.
    Using Variables • Wayto temporarily store bits of data • Necessity in almost every language • JavaScript variables are a bit different Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 196.
    Variable Declaration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 197.
    Variable Declaration • Notrequired, but you should do it Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 198.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 199.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 200.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 201.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 202.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; • Undefined until initialized Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 203.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; • Undefined until initialized • Can declare and initialize in one statement Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 204.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; • Undefined until initialized • Can declare and initialize in one statement  var count = 0; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 205.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; • Undefined until initialized • Can declare and initialize in one statement  var count = 0;  var minMsgID = 32629; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 206.
    Variable Declaration • Notrequired, but you should do it • Untyped, so simple: use var with identifier  var count;  var minMsgID;  var lastName; • Undefined until initialized • Can declare and initialize in one statement  var count = 0;  var minMsgID = 32629;  var lastName = "Kiely"; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 207.
    Variable Declaration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 208.
    Variable Declaration • Multiplevariables in single var statement Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 209.
    Variable Declaration • Multiplevariables in single var statement  var count = 0, minMsgID = 32629, lastName = "Kiely"; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 210.
    Variable Declaration • Multiplevariables in single var statement  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Break onto multiple lines Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 211.
    Variable Declaration • Multiplevariables in single var statement  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Break onto multiple lines  var count = 0, minMsgID = 32629, lastName = "Kiely"; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 212.
    Variable Declaration • Multiplevariables in single var statement  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Break onto multiple lines  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Declare and initialize within loops Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 213.
    Variable Declaration • Multiplevariables in single var statement  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Break onto multiple lines  var count = 0, minMsgID = 32629, lastName = "Kiely"; • Declare and initialize within loops  for (var i = 2; i <= 36; i++) console.log("Base " + i + ": " + num.toString(i)); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 214.
    Variable Cautions andGotchas Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 215.
    Variable Cautions andGotchas • Variable can hold any type during execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 216.
    Variable Cautions andGotchas • Variable can hold any type during execution  var count = 0; <program code> count = "Don"; <more program code> count = false <yet more code> count = "The Duke of Windsor"; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 217.
    Variable Cautions andGotchas • Variable can hold any type during execution  var count = 0; <program code> count = "Don"; <more program code> count = false <yet more code> count = "The Duke of Windsor"; • Be careful splitting across multiple lines! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 218.
    Variable Cautions andGotchas • Variable can hold any type during execution  var count = 0; <program code> count = "Don"; <more program code> count = false <yet more code> count = "The Duke of Windsor"; • Be careful splitting across multiple lines!  var count = 0 minMsgID = 32629, lastName = "Kiely"; Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 219.
    Variable Scope Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 220.
    Variable Scope • Scopeis section of code where variable is defined and accessible Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 221.
    Variable Scope • Scopeis section of code where variable is defined and accessible • Two scopes in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 222.
    Variable Scope • Scopeis section of code where variable is defined and accessible • Two scopes in JavaScript  Global Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 223.
    Variable Scope • Scopeis section of code where variable is defined and accessible • Two scopes in JavaScript  Global  Local Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 224.
    Variable Scope • Scopeis section of code where variable is defined and accessible • Two scopes in JavaScript  Global  Local • Local variable has function scope in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 225.
    Variable Hoisting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 226.
    Variable Hoisting • Functionscope has an important implication Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 227.
    Variable Hoisting • Functionscope has an important implication • All local variables declared within a function Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 228.
    Variable Hoisting • Functionscope has an important implication • All local variables declared within a function  Visible throughout the body of the function Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 229.
    Variable Hoisting • Functionscope has an important implication • All local variables declared within a function  Visible throughout the body of the function • Side effect: all local variables are visible even before they are declared Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 230.
    Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 231.
    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
  • 232.
    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
  • 233.
    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
  • 234.
    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

Editor's Notes