SlideShare una empresa de Scribd logo
1 de 234
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

Más contenido relacionado

La actualidad más candente

Pickup brown truck side view powerpoint presentation templates.
Pickup brown truck side view powerpoint presentation templates.Pickup brown truck side view powerpoint presentation templates.
Pickup brown truck side view powerpoint presentation templates.SlideTeam.net
 
Pickup brown truck side view powerpoint ppt templates.
Pickup brown truck side view powerpoint ppt templates.Pickup brown truck side view powerpoint ppt templates.
Pickup brown truck side view powerpoint ppt templates.SlideTeam.net
 
Blue truck top view powerpoint presentation templates
Blue truck top view powerpoint presentation templatesBlue truck top view powerpoint presentation templates
Blue truck top view powerpoint presentation templatesSlideTeam.net
 
Three extending circles powerpoint diagrame templates 0712
Three extending circles powerpoint diagrame templates 0712Three extending circles powerpoint diagrame templates 0712
Three extending circles powerpoint diagrame templates 0712SlideTeam.net
 
Red truck top view powerpoint presentation slides.
Red truck top view powerpoint presentation slides.Red truck top view powerpoint presentation slides.
Red truck top view powerpoint presentation slides.SlideTeam.net
 
Red truck top view powerpoint ppt templates.
Red truck top view powerpoint ppt templates.Red truck top view powerpoint ppt templates.
Red truck top view powerpoint ppt templates.SlideTeam.net
 
Red truck top view powerpoint ppt slides.
Red truck top view powerpoint ppt slides.Red truck top view powerpoint ppt slides.
Red truck top view powerpoint ppt slides.SlideTeam.net
 
Red truck top view powerpoint presentation templates.
Red truck top view powerpoint presentation templates.Red truck top view powerpoint presentation templates.
Red truck top view powerpoint presentation templates.SlideTeam.net
 
Word Processing :-)
Word Processing :-)Word Processing :-)
Word Processing :-)Kim :-)
 
Red beetle car vehicle transportation side view powerpoint presentation templ...
Red beetle car vehicle transportation side view powerpoint presentation templ...Red beetle car vehicle transportation side view powerpoint presentation templ...
Red beetle car vehicle transportation side view powerpoint presentation templ...SlideTeam.net
 
Red beetle car vehicle transportation side view powerpoint presentation slides.
Red beetle car vehicle transportation side view powerpoint presentation slides.Red beetle car vehicle transportation side view powerpoint presentation slides.
Red beetle car vehicle transportation side view powerpoint presentation slides.SlideTeam.net
 
Red beetle car vehicle transportation side view powerpoint ppt templates.
Red beetle car vehicle transportation side view powerpoint ppt templates.Red beetle car vehicle transportation side view powerpoint ppt templates.
Red beetle car vehicle transportation side view powerpoint ppt templates.SlideTeam.net
 
Red beetle car vehicle transportation side view powerpoint ppt slides.
Red beetle car vehicle transportation side view powerpoint ppt slides.Red beetle car vehicle transportation side view powerpoint ppt slides.
Red beetle car vehicle transportation side view powerpoint ppt slides.SlideTeam.net
 
6 stages gears process powerpoint slides ppt templates
6 stages gears process powerpoint slides ppt templates6 stages gears process powerpoint slides ppt templates
6 stages gears process powerpoint slides ppt templatesSlideTeam.net
 
Green beetle car vehicle transportation side view powerpoint ppt slides.
Green beetle car vehicle transportation side view powerpoint ppt slides.Green beetle car vehicle transportation side view powerpoint ppt slides.
Green beetle car vehicle transportation side view powerpoint ppt slides.SlideTeam.net
 
Green beetle car vehicle transportation side view powerpoint presentation sli...
Green beetle car vehicle transportation side view powerpoint presentation sli...Green beetle car vehicle transportation side view powerpoint presentation sli...
Green beetle car vehicle transportation side view powerpoint presentation sli...SlideTeam.net
 
Green beetle car vehicle transportation side view powerpoint ppt templates.
Green beetle car vehicle transportation side view powerpoint ppt templates.Green beetle car vehicle transportation side view powerpoint ppt templates.
Green beetle car vehicle transportation side view powerpoint ppt templates.SlideTeam.net
 
Green beetle car vehicle transportation side view powerpoint presentation tem...
Green beetle car vehicle transportation side view powerpoint presentation tem...Green beetle car vehicle transportation side view powerpoint presentation tem...
Green beetle car vehicle transportation side view powerpoint presentation tem...SlideTeam.net
 

La actualidad más candente (18)

Pickup brown truck side view powerpoint presentation templates.
Pickup brown truck side view powerpoint presentation templates.Pickup brown truck side view powerpoint presentation templates.
Pickup brown truck side view powerpoint presentation templates.
 
Pickup brown truck side view powerpoint ppt templates.
Pickup brown truck side view powerpoint ppt templates.Pickup brown truck side view powerpoint ppt templates.
Pickup brown truck side view powerpoint ppt templates.
 
Blue truck top view powerpoint presentation templates
Blue truck top view powerpoint presentation templatesBlue truck top view powerpoint presentation templates
Blue truck top view powerpoint presentation templates
 
Three extending circles powerpoint diagrame templates 0712
Three extending circles powerpoint diagrame templates 0712Three extending circles powerpoint diagrame templates 0712
Three extending circles powerpoint diagrame templates 0712
 
Red truck top view powerpoint presentation slides.
Red truck top view powerpoint presentation slides.Red truck top view powerpoint presentation slides.
Red truck top view powerpoint presentation slides.
 
Red truck top view powerpoint ppt templates.
Red truck top view powerpoint ppt templates.Red truck top view powerpoint ppt templates.
Red truck top view powerpoint ppt templates.
 
Red truck top view powerpoint ppt slides.
Red truck top view powerpoint ppt slides.Red truck top view powerpoint ppt slides.
Red truck top view powerpoint ppt slides.
 
Red truck top view powerpoint presentation templates.
Red truck top view powerpoint presentation templates.Red truck top view powerpoint presentation templates.
Red truck top view powerpoint presentation templates.
 
Word Processing :-)
Word Processing :-)Word Processing :-)
Word Processing :-)
 
Red beetle car vehicle transportation side view powerpoint presentation templ...
Red beetle car vehicle transportation side view powerpoint presentation templ...Red beetle car vehicle transportation side view powerpoint presentation templ...
Red beetle car vehicle transportation side view powerpoint presentation templ...
 
Red beetle car vehicle transportation side view powerpoint presentation slides.
Red beetle car vehicle transportation side view powerpoint presentation slides.Red beetle car vehicle transportation side view powerpoint presentation slides.
Red beetle car vehicle transportation side view powerpoint presentation slides.
 
Red beetle car vehicle transportation side view powerpoint ppt templates.
Red beetle car vehicle transportation side view powerpoint ppt templates.Red beetle car vehicle transportation side view powerpoint ppt templates.
Red beetle car vehicle transportation side view powerpoint ppt templates.
 
Red beetle car vehicle transportation side view powerpoint ppt slides.
Red beetle car vehicle transportation side view powerpoint ppt slides.Red beetle car vehicle transportation side view powerpoint ppt slides.
Red beetle car vehicle transportation side view powerpoint ppt slides.
 
6 stages gears process powerpoint slides ppt templates
6 stages gears process powerpoint slides ppt templates6 stages gears process powerpoint slides ppt templates
6 stages gears process powerpoint slides ppt templates
 
Green beetle car vehicle transportation side view powerpoint ppt slides.
Green beetle car vehicle transportation side view powerpoint ppt slides.Green beetle car vehicle transportation side view powerpoint ppt slides.
Green beetle car vehicle transportation side view powerpoint ppt slides.
 
Green beetle car vehicle transportation side view powerpoint presentation sli...
Green beetle car vehicle transportation side view powerpoint presentation sli...Green beetle car vehicle transportation side view powerpoint presentation sli...
Green beetle car vehicle transportation side view powerpoint presentation sli...
 
Green beetle car vehicle transportation side view powerpoint ppt templates.
Green beetle car vehicle transportation side view powerpoint ppt templates.Green beetle car vehicle transportation side view powerpoint ppt templates.
Green beetle car vehicle transportation side view powerpoint ppt templates.
 
Green beetle car vehicle transportation side view powerpoint presentation tem...
Green beetle car vehicle transportation side view powerpoint presentation tem...Green beetle car vehicle transportation side view powerpoint presentation tem...
Green beetle car vehicle transportation side view powerpoint presentation tem...
 

Similar a JavaScript: Values, Types and Variables

.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data TypesLearnNowOnline
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow controlLearnNowOnline
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsLearnNowOnline
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniquesLearnNowOnline
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptLearnNowOnline
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity FrameworkLearnNowOnline
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryLearnNowOnline
 
Asynchronous Programming
Asynchronous ProgrammingAsynchronous Programming
Asynchronous ProgrammingLearnNowOnline
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5LearnNowOnline
 
Building Large Sustainable Apps
Building Large Sustainable AppsBuilding Large Sustainable Apps
Building Large Sustainable AppsBuğra Oral
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET FrameworkLearnNowOnline
 
TDD - for people who don't need it
TDD - for people who don't need itTDD - for people who don't need it
TDD - for people who don't need itChoon Keat Chew
 
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Simplilearn
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony Mojo Lingo
 
Lecture 3 object-oriented design
Lecture 3    object-oriented designLecture 3    object-oriented design
Lecture 3 object-oriented designNada G.Youssef
 

Similar a JavaScript: Values, Types and Variables (20)

Generics
GenericsGenerics
Generics
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data Types
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow control
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniques
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
WPF Binding
WPF BindingWPF Binding
WPF Binding
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQuery
 
Asynchronous Programming
Asynchronous ProgrammingAsynchronous Programming
Asynchronous Programming
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
Building Large Sustainable Apps
Building Large Sustainable AppsBuilding Large Sustainable Apps
Building Large Sustainable Apps
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET Framework
 
Online exam software
Online exam softwareOnline exam software
Online exam software
 
TDD - for people who don't need it
TDD - for people who don't need itTDD - for people who don't need it
TDD - for people who don't need it
 
SQL Server: Security
SQL Server: SecuritySQL Server: Security
SQL Server: Security
 
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony
 
Lecture 3 object-oriented design
Lecture 3    object-oriented designLecture 3    object-oriented design
Lecture 3 object-oriented design
 

Más de LearnNowOnline

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesLearnNowOnline
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionLearnNowOnline
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDELearnNowOnline
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 
WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with DataLearnNowOnline
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document ManagementLearnNowOnline
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathLearnNowOnline
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collectionsLearnNowOnline
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programmingLearnNowOnline
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCLearnNowOnline
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignLearnNowOnline
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVCLearnNowOnline
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User InterfaceLearnNowOnline
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5LearnNowOnline
 

Más de LearnNowOnline (19)

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data Protection
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with Data
 
A tour of SQL Server
A tour of SQL ServerA tour of SQL Server
A tour of SQL Server
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document Management
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPath
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collections
 
Web API HTTP Pipeline
Web API HTTP PipelineWeb API HTTP Pipeline
Web API HTTP Pipeline
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVC
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction Design
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVC
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User Interface
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
 

Último

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Último (20)

YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

JavaScript: Values, Types and Variables

  • 1. Values, Types, and Variables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Objectives • Learn about JavaScript types and comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4. 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
  • 5. 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
  • 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 • Defines types 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 • 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. Primary Types in JavaScript Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. JavaScript Numbers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. JavaScript Numbers • All numbers are 64-bit floating-point values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. Integer Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32. Integer Literals • Represent either as base 10 or hexadecimal Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 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 • Either string is valid Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68. 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
  • 69. 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
  • 70. 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
  • 71. 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
  • 72. String Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 73. String Literals • All the following are valid string literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 74. String Literals • All the following are valid string literals  "" // an empty string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 75. 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
  • 76. 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
  • 77. 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
  • 78. 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
  • 79. Line Breaks in String Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 80. 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
  • 81. 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
  • 82. 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
  • 83. 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
  • 84. 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
  • 85. 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
  • 86. Escape Sequences in String Literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87. 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
  • 88. 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
  • 89. 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
  • 90. JavaScript Escape Sequences Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91. 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
  • 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 and Logical Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 116. Boolean Methods and Logical • Boolean values have two methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 117. 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
  • 118. 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
  • 119. 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
  • 120. 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
  • 121. 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
  • 122. 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
  • 123. Special Values: null and undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 124. Special Values: null and undefined • null Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 125. Special Values: null and undefined • null  Language keyword Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126. 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
  • 127. 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
  • 128. 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
  • 129. 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
  • 130. 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
  • 131. 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
  • 132. undefined Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 133. undefined • JavaScript uses in a few different ways Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 134. 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
  • 135. 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
  • 136. 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
  • 137. 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
  • 138. 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
  • 139. 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
  • 140. Use null or undefined? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 141. Use null or undefined? • Both mean absence of value Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 142. 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
  • 143. 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
  • 144. 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
  • 145. 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
  • 146. 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
  • 147. 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
  • 148. 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
  • 149. 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
  • 150. Type Comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 151. Type Comparisons • JavaScript compares primitive values and object values differently Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 152. 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
  • 153. 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
  • 154. Object Comparisons Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 155. Object Comparisons • JavaScript compares objects by reference Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 156. 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
  • 157. 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
  • 158. Type Conversions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 159. Type Conversions • Feature that makes JavaScript easy and hard Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 160. 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
  • 161. 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
  • 162. 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
  • 163. 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
  • 164. 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
  • 165. 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
  • 166. 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
  • 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 and Parsing Functions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 177. 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
  • 178. 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
  • 179. 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
  • 180. Conversions Using Wrapper Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 181. Conversions Using Wrapper Objects • Number, String, Boolean, and Object wrapper objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 182. 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
  • 183. 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
  • 184. 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
  • 185. 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
  • 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 • Way to temporarily store bits of data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 194. 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
  • 195. 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
  • 196. Variable Declaration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 197. Variable Declaration • Not required, but you should do it Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 198. 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
  • 199. 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
  • 200. 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
  • 201. 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
  • 202. 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
  • 203. 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
  • 204. 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
  • 205. 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
  • 206. 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
  • 207. Variable Declaration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 208. Variable Declaration • Multiple variables in single var statement Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 209. 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
  • 210. 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
  • 211. 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
  • 212. 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
  • 213. 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
  • 214. Variable Cautions and Gotchas Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 215. Variable Cautions and Gotchas • Variable can hold any type during execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 216. 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
  • 217. 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
  • 218. 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
  • 219. Variable Scope Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 220. 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
  • 221. 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
  • 222. 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
  • 223. 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
  • 224. 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
  • 225. Variable Hoisting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 226. Variable Hoisting • Function scope has an important implication Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 227. 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
  • 228. 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
  • 229. 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
  • 230. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 231. 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
  • 232. 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
  • 233. 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
  • 234. 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

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. DEMO: rest of section\n
  53. DEMO: rest of section\n
  54. DEMO: rest of section\n
  55. DEMO: rest of section\n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. DEMO: rest of section, String Operations\n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. DEMO: rest of section\n
  114. DEMO: rest of section\n
  115. DEMO: rest of section\n
  116. DEMO: rest of section\n
  117. DEMO: rest of section\n
  118. DEMO: rest of section\n
  119. DEMO: rest of section\n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. DEMO: rest of section\n
  136. DEMO: rest of section\n
  137. DEMO: rest of section\n
  138. DEMO: rest of section\n
  139. DEMO: rest of section\n
  140. DEMO: rest of section\n
  141. DEMO: rest of section\n
  142. DEMO: rest of section\n
  143. DEMO: rest of section\n
  144. DEMO: rest of section, Object Comparisons\n
  145. DEMO: rest of section, Object Comparisons\n
  146. DEMO: rest of section, Object Comparisons\n
  147. DEMO: rest of section\n
  148. DEMO: rest of section\n
  149. DEMO: rest of section\n
  150. \n
  151. \n
  152. \n
  153. \n
  154. DEMO: Implicit Type Conversions, Equality Conversions\n
  155. DEMO: Implicit Type Conversions, Equality Conversions\n
  156. DEMO: Implicit Type Conversions, Equality Conversions\n
  157. DEMO: Implicit Type Conversions, Equality Conversions\n
  158. DEMO: Implicit Type Conversions, Equality Conversions\n
  159. DEMO: Implicit Type Conversions, Equality Conversions\n
  160. DEMO: Implicit Type Conversions, Equality Conversions\n
  161. DEMO: Implicit Type Conversions, Equality Conversions\n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. DEMO: rest of section\n
  174. DEMO: rest of section\n
  175. DEMO: rest of section\n
  176. DEMO: rest of section\n
  177. DEMO: rest of section\n
  178. DEMO: rest of section\n
  179. DEMO: rest of section\n
  180. DEMO: rest of section\n
  181. DEMO: rest of section\n
  182. DEMO: rest of section\n
  183. \n
  184. \n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. \n
  206. \n
  207. \n
  208. \n
  209. \n
  210. DEMO: rest of section\n
  211. DEMO: rest of section\n
  212. DEMO: rest of section\n
  213. DEMO: rest of section\n
  214. DEMO: rest of section\n
  215. DEMO: rest of section\n
  216. DEMO: rest of section\n
  217. DEMO: rest of section\n
  218. DEMO: rest of section\n
  219. DEMO: rest of section\n
  220. DEMO: rest of section\n
  221. DEMO: rest of section\n
  222. DEMO: rest of section\n