Objects in Javascript

 

Objects in Javascript


1.Introduction of Objects
2.Definition of Object
3.Example Car Example
4.Object Property and Methods
5.Types of Objects 
     1.Built In Object
     2.User Defined Objects

 Introduction    

  JavaScript is known as object oriented scripting language. Object plays important role i.e.in JavaScript object is everything. An object having both properties and methods. 

Definition of Object

All real(tangible) things are called as objects.

Example car object.

    Every car has different properties like model,color etc. Also methods like start,stop etc. Every car has same properties but different values. Methods are also same but perform differently.  

Example-car as an object.

1.properties -    name,model,color etc.

2.methods-    start,stop etc. 

Properties and methods of objects are accessed with ‘.’ Operator.

 

Objects In Javascript Video

 Example-

1.Property

    For accessing properties of an object,we write here as follows-

    objectname.propertyname

    e.g.var sms="Welcome to Javascript";

            var len=sms.length;

Result is 21  Here blankspace is also calculated 1 character in it in result. 

car.name=Maruti

car.model=Swift Dzire

car.color=red

2.Methods

    In javascript we call a method and written as follows-

        objectname.methodname()

    E.g.var sms="Welcome to Javascript"

    var u=sms.toLowerCase();

    Result is welcome to javascript 

car.start()

car.stop()

Types of objects in Javascript-

There are two of objects in javascript namely,

1.Built-in object 

    In Javascript there are 4 built in functions namely Array,Date,Math and String. Every object has special purpose properties and methods associated with it.

2.User defined object

    As per user requirement user create its own objects in JavaScript. For creation of user defined objects 'new' keyword is used.

    e.g.var cdate=new Date();


Previous
Next Post »

Please Comment and Share. ConversionConversion EmoticonEmoticon