Whole Assignments

SIGN UP TASK PART ONE AND TWO

History

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 thought 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. In doing so he created a language called LiveScript, a mainly browser based language that added dynamic content to web pages. Netscape and Sun were originally rivalries but in an effort to trump Microsoft decided to work together on LiveScript. After much debate they changed then name of LiveScript to JavaScript. Some say this was a slight knock at Sun from the Netscape’s programmers (but has not been proven). So this is where the similarity in names comes from.

Java was such a hit at the time that the media was quick to take notice of JavaScript thinking it was a subset of Java. This confusion was actually great for JavaScript as it gained plenty of attention from both the media and programmers alike.  At the time Microsoft caught wind of the praise JavaScript was receiving and wanted to get in on the action too. So they created a language called JS which was a reverse engineered version of JavaScript. Many people think they are two different languages but they are in truth the same thing.

When Netscape found out about this they went to Europe  to the ECMA to try to gain rights over JavaScript’s standardization process. However Microsoft had some of their own people on the board and Netscape lost power with in the first day of the ECMA meeting.

After Microsoft gained control they worked with ECMA to set the standards for JS. While doing so they decided to keep the mistakes that Netscape had made in the programming language. The reason for this is they wanted to be sure that the previous programs made in the language would not break. This is why JavaScript still has many weaknesses, and pitfalls in the language.

In short JavaScript has come along way since its birth, and is still kicking after fifteen years of being alive. Despite it’s downfalls, it’s still a wonderful way to add dynamic content to web pages and sites. This is proven in the fact that this powerful language is one of the most widely used programming languages in the world.


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

-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: ?:

Sourced from (http://www.diycomputerscience.com/courses/course/JAVASCRIPT/competency/185) Douglas Crockford

Sign Up Task: three examples of how to add 2+2 with JavaScript

link to working example

<script language=”JavaScript”>

//program one

document.writeln (“2 + 2 = 4″);

alert (2 + 2);

</script>

____________________________________________________

<script language=”JavaScript”>

//program two

var number1 = 2;

var number2 = 2;

document.writeln(number1 + ” + ” + number2 + ” = ” + number1 + number2);

alert(number1 + number2);

</script>

____________________________________________________

<script language=”JavaScript”>

//program three

var number1 = 2;

var number2 = 2;

var answer = number1 + number2;

document.writeln(number1 + ” + ” + number2 + ” = ” + answer);

alert(answer);

</script>

____________________________________________________

Leave a comment