JAVASCRIPT – Functions – CHAPTER 3

A function is a block of Javascript code that is defined once and called many numbers of times.

Defining Functions:

function callMe(index){

var a=index;

console.log(a);

}

callMe(5);//Invoking functions

//Object Literals

var o{

var a;

add:function(){

this.c=this.a+2;

}

};

o.add();

–Chapter 3 END

JAVASCRIPT – Functions – CHAPTER 3

JAVASCRIPT – Arrays – CHAPTER 2

An Array is a collection of values. Each value are accessed by index value.

Creating Arrays:

var empty = []; // An array with no elements
var primes = [2, 3, 5, 7, 11]; // An array with 5 numeric elements

Reading Arrays:

var a=[1,2,3];

a[0]//Read elememt 0.

–Chapter 2 END.

JAVASCRIPT – Arrays – CHAPTER 2

JavaScript – Object – Chapter 1

Object Literals:

var x={};

var point={x=0,y=0};

Creating Objects with new:

var js-new Object();

Prototype:

Every Javascript object has a second javascript object associated with it. The second object is known as prototype.

Object.prototype

Object.create():

That creates a new object.

var o1 = Object.create({x:1, y:2});// o1 inherits x and y

Inheritance

var o{

a:2,

m:function(){

return this.a+1;

}

};

var  p= Object.create(o);

p.a=10;

p.m();//will trace 11.

 JSON Serializing Objects:

ECMAScript 5 provides a method JSON.stringfy() and JSON.parser() to seralize and restore Javscript objects.

o = {x:1, y:{z:[false,null,””]}}; // Define a test object
s = JSON.stringify(o); // s is ‘{“x”:1,”y”:{“z”:[false,null,””]}}’
p = JSON.parse(s); // p is a deep copy of o

—Chapter 1 END.

JavaScript – Object – Chapter 1