Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Created June 21, 2015 20:33
Show Gist options
  • Save RobAWilkinson/abecf995a543761c2213 to your computer and use it in GitHub Desktop.
Save RobAWilkinson/abecf995a543761c2213 to your computer and use it in GitHub Desktop.

###Objectives:

  • Understand why JavaScript is so awesome
  • Understand what an Object is
  • Apply OOP principle to pseudocode an object
  • Create an object in Sublime Text

JavaScript: Intro

  1. NOT to be confused with Java
  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.

#Why is JavaScript important?

  1. All browsers have JavaScript interpreters built in!
  2. There are 3 ultra-fast JavaScript engines around (FireFox SpiderMonkey, Google V8, and Safari JavaScriptCore) fiercely competing to become faster and faster
  3. JavaScript is most popular programming language in the world!

##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.


#Variables

Variables are containers for storing data values. Variables MUST be identified with unique names, called identifiers

  • case-sensitive
  • begin with a letter
  • contain letters, digits, underscores, and dollar signs
var five = 5;	
var rob = "Instructor";

Functions

###Functions are a way of actually doing things


function sayHello() {
  console.log('hello');
}
// then we run our function after we create it
sayHello();

// we can also pass things into our function
function sayHello(name) {
  console.log('hello ' + name);
}
sayHello('rob');
// or variables

var robName = 'rob';

sayHello(robName);

#Objects

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

Car object

  • attributes
    • color
    • price
    • top speed
  • behaviors
    • drive
    • stop

		// Created a variable with the object, car!
		var car = {}; 
		car.color = "blue";
		car.price = 50000;

		car.drive = function(){
			console.log("Drive");
		}
		
		car.stop = function(){
			console.log("Stop");
		}
		
		car.turnOnLights = function(){
			console.log("Lights are on");
		}		

#Arrays

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

// 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