JavaScript – Introduction – All Entities Are Created Equal



JavaScript – Introduction – All Entities Are Created Equal

4 1


javascript


On Github phoenix0665 / javascript

JavaScript

Introduction

The Punny Language

Mocha AKA LiveScript AKA JavaScript AKA ECMAScript

Birth Place

Netscape HQ 1999 (Source: Flickr)

The Prototype

Brendan Eich

Engines

  • Chakra - IE > 9
  • SpiderMonkey - Gecko
  • V8 - Google Chrome
  • Nitro - Safari

All Entities Are Created Equal

Objects

								
	var number = 1;
	var string = "Hello";
	var boolean_value = true;

	function helloWorld(){
	  alert("Hello World!!");
	}
								
							

Conditions Always Apply

								
	null

	undefined
								
							

Dynamic Types

								
	var number = 1; //Number
	var hello = "Hello!!"; //String
	var boolean_true = true; //Boolean True
	var boolean_false = false; //Boolean False

	null

	undefined
								
							

Try not. Do or do not. There is no try.

								
	function importantLesson(){
		a = 1;
		var b = 2;
	}

	importantLesson();

	alert(a);
	alert(b);
								
							

Truthy and Falsy

Falsy

								
	false
	0
	""
	null
	undefined
	NaN
								
							

Truthy

Eliminate all other factors, and the one which remains must be the truth.

Logical Operators

								
	true == true //Equals
	true && true //And
	true || true //Or
	!true //Not
	true === "true" //What?
	true !== "true" //What?
	!!"true" //What?
	!!!"true" //What?
								
							

Upside Down

Variables

								
	var string = "Hello World!!"; //String Object
	var number = 10; //Number Object

								
							

Functions

								
	function funcName(args){
		//Logic
	}

	var funcName = function(args){
		//Logic
	};

	funcName(args1, args2); // Dynamic Arguments
	funcName(args);


	(function (){
		console.log("Halo!!");
	})(); //Self Excuting Functions or Dog Balls


								
							

Arrays

								
	var ar = []; //Array
	var ar_2 = new Array(); //Bigger way to create an array
								
							

Objects

								
	var obj = {}; //Object
								
							

Closures

								
	var printFooBar = function(){
		var foo = "foo";

		var appendBar = function(){  //Closure
			console.log(foo + "bar");
		};

		appendBar();
	};
								
							

Class

							
	//Class
	var Car = function(){
		var name = null;

		var setModelName = function(model){
			name = model;
		};

		var getModelName = function(){
			return name;
		};

		return {
			setModelName: setModelName,
			getModelName: getModelName
		};
	};


	var figo = new Car();
	figo.setModelName("Figo");
	figo.getModelName();


							
						

Prototypes

								
	Object.prototype;
								
							

Debugging

								
	debugger;
								
							

DOM

							
	window
	window.history
	window.location
	window.document
							
						

Events

							
	var menu = document.getElementById("menu");

	var showMenu = function(event){
		event.preventDefault();

		event.target.className = "";
	};

	menu.addEventListener('click', showMenu, false);
							
						

AJAX

							
	var httpRequest = new XMLHTTPRequest();

	var callback = function(){
		if(httpRequest.readyState === 4){
			if(httpRequest.status === 200){
				alert(httpRequest.responseText);
			}else{
				alert("Something Went wrong");
			}
		}
	};

	httpRequest.onreadystatechange = callback;

	httpRequest.open("GET", "recipes/vad-pav.json");
	httpRequest.send();
							
						

delete Session.javascript;