1.

What Are Different Two Ways Of Creating An Object?

Answer»

OBJECT LITERALS: This is the most common way to create the object with object literal.

For Example:

var emptyObj= {};

Object Constructor: It is way to create object using object constructor and the constructor is used to INITIALIZE new object.

For Example:

Var obj = new Object();

Global variable: A variable which can be variable from any where of the page.

Following are different two ways.

First Way Declare the JavaScript variable at the top of JavaScript code and out of function & OBJECTS.

var globalVariable1 ='This is global variable 1'
Second WayDeclare a varaible without "var" in Function.
function testfunction(){
globalVariable2 ='This is global variable 2'
}

Object Literals: This is the most common way to create the object with object literal.

For Example:

var emptyObj= {};

Object Constructor: It is way to create object using object constructor and the constructor is used to initialize new object.

For Example:

Var obj = new Object();

Global variable: A variable which can be variable from any where of the page.

Following are different two ways.

First Way Declare the JavaScript variable at the top of JavaScript code and out of function & objects.

var globalVariable1 ='This is global variable 1'
Second WayDeclare a varaible without "var" in Function.
function testfunction(){
globalVariable2 ='This is global variable 2'
}



Discussion

No Comment Found