Javascript

Topic: JS Objects

What is a javascript object ?

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.propNameExample: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();

Browse random answers: