1. Syntax

  2. JavaScript Syntax

  3. Statements

    Separate lines:

    
    Statement 1
    Statement 2
    

    Separated by semi-colons:

    
    Statement 1;Statement 2
    

    Both:

    
    Statement 1;
    Statement 2;
    
  4. Comments

    A statement that isn't executed.

    
    Statement 1;
    // comment
    Statement 2;
    
  5. Variables

    A label that stands for a value, even if the value changes.

    Numbers, strings, Boolean values:

    
    var age = 34;
    var name = "Jeremy";
    var name = 'Jeremy';
    var height = '5\'10"';
    var male = true;
    
  6. Variables

    JavaScript is a weakly typed language

    
    var foo = 37.5;
    var foo = "bar";
    
  7. Arrays

    A variable that is a collection of variables.

    
    var fruit = new Array();
    fruit[0] = "apple";
    fruit[1] = "orange";
    fruit[2] = "banana";
    

    Combine declaring and setting:

    
    var fruit = new Array("apple","orange","banana");
    
  8. Arrays

    The length of an array.

    
    var fruit = new Array("apple","orange","banana");
    alert(fruit.length);
    

    Alert: 3

  9. Arrays

    
    var fruit = new Array("apple","orange","banana");
    alert(fruit[0]);
    

    Alert: apple

  10. Arrays

    for (initial condition; test condition; change operation)

    
    var fruit = new Array("apple","orange","banana");
    
    for (var i=0; i<fruit.length; i++) {
      alert(fruit[i]);
    }
    

    Alert: apple

    Alert: orange

    Alert: banana

  11. Functions

    A self-contained series of statements

    
    function functionName (arguments) {
      Statements;
    }
    
  12. Functions

    
    function multiply(x,y) {
      var result = x * y;
      return result;
    }
    
    var mynum = multiply(2,6);
    alert(mynum);
    

    Alert: 12

  13. Variable scope

    
    function multiply(x,y) {
      var result = x * y;
      return result;
    }
    
  14. Variable scope

    
    function multiply(x,y) {
      result = x * y;
      return result;
    }
    
    result = 10;
    
    var mynum = multiply(2,6);
    
    alert(mynum);
    
    alert(result);
    

    Alert: 12

    Alert: 12

  15. Objects

    Self-contained bundles of functions and variations.

    Dot syntax:

    
    object.property
    object.method()
    
  16. Objects

  17. Native objects

    The Math object

    
    Math.round(3.14);
    

    The round method of the Math object.

  18. Native objects

    The Array object

    
    Array.length;
    

    The length property of the Array object.

  19. Host objects

    The window object

    
    window.open("http://www.example.com/");
    

    The open method of the window object.

  20. Next...

    The document object

    Methods and properties of the document object...