Running JavaScript

It would be to your benefit to try running examples from class in a JS Engine yourself. Try them out! Make sure you understand how they work. Try changing them to see if you really do understand what is going on.

Browser JS versions are harder to deal with, but you can be sure that the examples will work in the Node.js version named below.

Node.js Version

You can find the Node.js runtime here. We’re using the LTS version: v6.11.X.

You definitely cannot expect the current version of Node.js (v8.5.0 as of this writing) to behave the same. Do not use that version.

You also cannot expect the version of Node.js that’s currently installed on campus machines (v0.10.25) to behave the same. Don’t use that one either.

Browser Version

This is harder to pin down.

Use a reasonably up-to-date browser (like Firefox on the campus Linux machines). You can open the developer console and type in there.

Lecture Outline

  1. Intro to JavaScript
    • Intro presentation
    • Basic facts
    • Types
      • Primitive types
      • Objects
    • Assignment
    • Arrays (which are objects)
    • Variable Hoisting
    • Scope
      • vars are function scoped
      • let and const are block scoped
    • Operators
      • Numeric
      • Assignment / Compound Assignment (+=, -=, etc)
      • Increment / Decrement
      • Comparison
  2. More Basic JavaScript
    • Strict Mode
    • Assignment

      var x = [];
      var y = x;
      
      y.push("Bananas");
      
      console.log(x);  // [ 'Bananas' ]
      
    • Primitives vs Objects
      • Primitive Wrapper Objects
        • Primitives are not objects, although you can use them as if they are.
      • Objects
    • Comparison pitfalls
      • Strict equality (===) vs. non-strict equality (==)
    • null vs undefined
  3. Even more basic JavaScript
    • Control Flow
      • if / else
      • False-y values
        • Values that are interpreted as false in an if statement
      • switch statement
    • Usage of typeof
    • null is not an object (despite all objections)
    • Looping
      • Counting (for)
      • Post-check (do...while)
      • Pre-check (while)
      • Labels
      • break and continue
      • Iterating over object properties (for...in)
      • Iterating over iterables (like Array and String) (for...of)
      • Iterating over an Array using for...each method
  4. Functions
    • Functions
      • Declarations
      • Facts and Terminology
      • Arguments
        • What if an arg is a primitive?
        • What if it’s an object?

          function f(arr) {
              arr.push("frog");
              arr = [];
              arr.push("potato");
          }
          
          let x = [1,2,3];
          f(x);
          console.log(x);  // [ 1, 2, 3, 'frog' ]
          
    • Anonymous Functions and Function Expressions
    • Arrow Functions
    • Function Scoping and Hoisting
    • Immediately Invoked Function Expressions (IIFEs)
    • Node.js modules
      • module.exports
      • require()
  5. Asynchronous Programming and the JavaScript Engine
    • Function Closures
    • How JavaScript code runs in a JavaScript Engine
      • Call stack
      • Message queue
      • Event loop
      • Node (JavaScript Engine)
  6. Object Oriented JS and ToDo App Last lecture of test material
    • Object Oriented JavaScript
      • Basic facts
      • Constructors
      • Adding methods to prototype
    • ToDo App
  7. Promises Prime bonus material
  8. Test, Tool Demonstration, and Yammering on about the Development Community