Objects
Objects are basically real world entity.In the real world like car is an object,mobile is an object etc. In javaScript objects are basically use to store multiple values at a time in the form of key and value pairs. Syntax: javaScript objects are declare just like a variables but objects property declare inside {}.
var objectName={properties};
Defination of an Object:
var employe={firstName:"joy",lastName:"anderson",age:30,address:"london"};
document.write(employe.firstName+""+employe.lastName+"from"+employe.address);
How to access object values
Generally we have two ways to access object values in javaScript.objectName.propertyName
objectName["propertyName"]
javaScript Object Methods
In javaScript objects we can also declare methods according to our requirement there is no problem at all.var employe={
firstName:"jhon",
lastName:"Anderson",
age:39,
address:"london"
fullName:function(){
return this.firstName+" "+this.lastName;
}
}
this keyword
this keyword in very important keyword in javsScript .this keyword is use to access current objects or properties. In the above exmaple this.firstName is showing current object firstName and this.lastName is showing current object lstName. without using this keyword we can not access current objects and properties.How to access object methods
We can object methods by using following syntax.objectName.methodName();
Objects by using new keyword
var a=new String();var b=new Boolean();