Values


Values


-Most of JavaScript’s data is separated in to things called values.
-There are six basic types of values.

  • Numbers
    • Only one number type (no integers)
    • 64-bit floating point
    • Does not map well to common understanding of arithmetic
    • NaN
      • Not a number
      • NaN = Nan = False
      • NaN not > NaN or < NaN
    • Number Function
      • Number(value)
      • convert a value such as string to a number if string cant be converted return NaN
    • ParseInt Function
      • ParseInt(value,10)
      • Converts the value into a number
      • The radix argument should be required as it tells what base to calculate
    • JS has a Separate Math Object (modeled on Java’s Math Class)
      • floor *most useful
      • abs
      • log
      • max
      • pow
      • random
      • round
      • sin
      • sqrt
      • absolute value
      • integer
      • logarithm
      • maximum
      • raise to a power
      • random number
      • nearest integer
      • sine
      • square root
  • Strings
    • Sequence of 0 or more 16-bit Characters (ucs-2 not quite UTF-16: Created before unicode have matured)
    • No Separate Character Type
    • Characters are represented as strings with a length of 1
    • Strings are immutable > once a string is made it can’t be modified
    • Similar strings are equal (==)
    • String literals can use single or double quotes
    • String Length
      • string.length
      • determines the number of 16-bit characters in a string
    • String Function
      • String(value)
      • converts value to a string (number function can do too, slightly more graceful)
    • String Methods
      • charAt
      • concat
      • indexOf
      • lastIndexOf
      • match
      • replace
      • search
      • slice
      • split
      • subString
      • toLowerCase
      • toUpperCase
  • Booleans
    • True
    • False
    • Boolean Function
      • boolean(value)
      • returns true if value is truthy
      • returns false if value is falsy
      • similar to !! prefix operator
  • Undefined
    • a value that isn’t even that
    • the default value for variables and parameters
    • the value of missing members in objects
    • Falsy Values
      • false
      • null
      • undefined
      • ” ” empty string
      • 0
      • NaN
      • All other values (including all objects) are truthy (beware of “0” and “false” these are often confused for false
  • Null
    • a value that isn’t anything
  • Objects (everything else)
    • Unification of Object and Hashtable
      • newObject()
      • produces and empty container of name/value pairs
        • a name can be any string, a value can be any value except undefined

Leave a comment