Wednesday, 27 April 2016

JavaScript Objects

A javaScript object is an entity having state and behavior (properties and method).
JavaScript is an object-based language. Everything is an object in JavaScript.
JavaScript is template based not class based. Here, we don't create class to get the object. But, we direct create objects.

Creating Objects in JavaScript
There are 3 ways to create objects.

  1. By object literal
  2. By creating instance of Object directly (using new keyword)
  3. By using an object constructor (using new keyword)
1) JavaScript Object by object literal


2)By creating instance of object 
var objectname=new Object();  

3) By using an Object constructor
The this keyword refers to the current object.

function student(id,name,age){;;
st=new student(103,"Vimal Jaiswal",12);
document.write(" "" "+st.age);

No comments :

Post a Comment