Skip to content

Instantly share code, notes, and snippets.

@stanleycyang
Created March 18, 2015 20:24
Show Gist options
  • Save stanleycyang/1ca803b6b2c5d2a9c698 to your computer and use it in GitHub Desktop.
Save stanleycyang/1ca803b6b2c5d2a9c698 to your computer and use it in GitHub Desktop.

###Objectives:

  1. Understand why JavaScript is so awesome

2) Understand what an Object is
3) Apply OOP principle to pseudocode an object
4) Create an object in Sublime Text

JavaScript: Intro

  1. NOT to be confused with Java (Activity: ask if people heard of JavaScript / Java. Are they the same thing?)

  2. Created in 10 days in May 1995 by Brendan Eich

  3. Original name was Mocha, a named chosen by Marc Andreessen (Founder of Netscape)

  4. ECMAScript (European Computer Manufacturers Association) is the name of the official standard, with JavaScript being the most well known of the implementations

##Why is JavaScript important?

1. All browsers have JavaScript interpreters built in!! No other have this tremendous advantage

2. There are 3 ultra-fast JavaScript engines around (FireFox SpiderMonkey, Google V8, and Safari JavaScriptCore) fiercely competing to become faster and faster

3. Fun Fact: You can make X-Box apps with HTML, CSS, and JavaScript!

4. JavaScript is most popular programming language in the world!

###Knowledge Check:

Spend two minutes telling the person to your side why JavaScript is awesome. Write down one reason on a word processor (MS Word, Notepad, etc.) on why JavaScript is awesome.

##What IS JavaScript?

JavaScript is a scripting language because it uses the browser to do its work. It is flexible, and allows for creative programming designs. This mix of features makes it a multi-paradigm language, supporting object-oriented programming.

###Objects

  • An Object-Oriented Programming (OOP) language is organized around objects.
  • Object-Oriented Programming is (OOP) focused around objects and its 1) attributes and 2) behaviors

###Activity

Name 5 objects in the room

###Activity

Name the attributes and behaviors of the objects

Example:

Objects Attributes Behaviors
Car Color, Price, Top speed Drive, stop, turn on lights

###Activity

Programming an object with dot notation

	// Created a variable with the object, car!
	var car = {}; 
	
	// assign attributes a car has
	
	car.color = "blue";
	car.topSpeed = 160;
	car.price = 50000;
	
	// assign behaviors to a car
	
	// functions allow you to write modular and reusable code. They can define the behaviors of an object
	
	car.drive = function(){
		console.log("Drive");
	}
	
	car.stop = function(){
		console.log("Stop");
	}
	
	car.turnOnLights = function(){
		console.log("Lights are on");
	}		

Variables

Variables are containers for storing data values.

Variables MUST be identified with unique names, called identifiers

  • Identifiers are case-sensitive

  • Identifiers must begin with a letter

  • Identifiers can contain letters, digits, underscores, and dollar signs

      var five = 5;	
      var Stanley = "Instructor";
      
      document.write(Stanley);
    

Activity

Turn to your partner and explain to them what an array is Choose 3 people to explain it.

An array is a data structure, AKA a way to organize data.

In JavaScript, it gives us the ability to store multiple values inside a single variable

// Call a cars variable contain cars
var cars = ['Infiniti', 'Volvo', 'BMW];


// print the variables out
document.write(cars[0]);
document.write(cars[1]);
document.write(cars[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment