What is a javascript object ?

 Posted by Bharathi Cherukuri on 6/18/2012 | Category: JavaScript Interview questions | Views: 2028 | Points: 40
Answer:

An object is a special kind of data, with a collection of properties and methods.
Let us discuss an example to have a clear idea:
A person is an object. Properties are the values associated with the object. The persons' properties include name, height, weight, age, skin tone, eye color, etc. All persons have these properties, but the values of those properties will differ from person to person.
Objects also have methods. Methods are the actions that can be performed on objects. The persons' methods could be eat(), sleep(), work(), play(), etc.

The syntax for accessing a property of an object is:

objName.propName


Example:

personObj.firstname="John";
personObj.lastname="Doe";
personObj.age=30;
personObj.eyecolor="blue";

document.write(personObj.firstname);



You can call a method with the following syntax:

objName.methodName()


Example:
personObj.sleep();


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response