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

JavaScript is Syntactically a C Family Language

 

JavaScript is Syntactically a C Family Language

-It differs from C mainly in its type system which allows functions to be values
Identifiers

  • Starts with a letter or _ or $
  • Followed by zero or more letters, digits, _ or $
  • Case Sensitibbe
  • by convention, all bariables, parameters, membersm and function names start with lower case
  • except for constructors which start with upper case
  • intitial _ should be reserved for implementations
  • @ should be reserved for machines (better to avoid)

Reserved Words

  • abstract
  • boolean break byte
  • case catch char class const continue
  • debugger default delete do double
  • else enum export extends
  • false final finally  float for function
  • goto
  • if implements import in instanceof int interfence
  • long
  • native new null
  • package private protected public
  • return
  • short static super switch synchronized
  • this throw throws transient true try typeof
  • var volatile void
  • while with

Comments

  • //  line comment
  • /* block comment */

Operators

  • Arithmetic: +   –   *   /   %
  • Comparison: ==    !-    <>    <=   >=
  • Logical: &&   ||   !
  • Bitwise:   $     |     ^    >>    >>>     <<
  • Ternary:  ?:

History of Javascript

You would have had to be living under a rock not to have at least heard of JavaScript. Now a days it is one of the most widely used programming languages in the world.  Surprisingly even with the mass popularity of JavaScript, it is still one of the world’s most misunderstood languages. If you though that JavaScript had anything to do with Sun Microsystem’s programming language Java, you would not be the first one.  You may be surprised to find out they have little to do with each other. To find out why their name’s are so familiar we have to dive deeper in the past to see how JavaScript was born and evolved.

Brendan Eich was hired in 1995 by Netscape to create a language that would make Java more accessible to none programmers.