How do you create a new object in JavaScript?

Answers were Sorted based on User's Feedback



How do you create a new object in JavaScript?..

Answer / sri

The following function can be used as demonstrated to create
an object of class myobject:

function myobject() {
this.containedValue = 0;
this.othercontainedValue = 0;
this.anothercontainedValue = 0;
}

var mything = new myobject();
And there you go, mything is now an instance of class
myobject. It will have the following properties, all of
which will be 0:

* mything.containedValue
* mything.othercontainedValue
* mything.anothercontainedValue

You could also now write
myobject.prototype.newContainedValue = someValue; and all
instances of class myobject will have the property
newContainedValue with value someValue.

Is This Answer Correct ?    7 Yes 4 No

How do you create a new object in JavaScript?..

Answer / nidz

var myObject={} this also creates a new object

Is This Answer Correct ?    4 Yes 2 No

How do you create a new object in JavaScript?..

Answer / elan

var newObject;

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More JavaScript Interview Questions

Which built-in method returns the string representation of the number’s value?

0 Answers  


What is scope variable in javascript?

0 Answers  


Which built-in method returns the calling string value converted to lower case?

0 Answers  


What is innertext javascript?

0 Answers  


How do I view javascript files in chrome?

0 Answers  






How to detect the OS on the client machine in JavaScript?

0 Answers  


What are the valid scopes of a variable in JavaScript?

0 Answers  


Write JavaScript code to use file system in binary format?

0 Answers  


How does javascript work?

0 Answers  


What does the following statement declares?

0 Answers  


Create a new javascript object with the keys of “fname” equal to your first name, “lname” equal to your last name, and “fcolors” equal to and array of 3 of your favorite colors. Assign this object to a variable called “me” and log it to the console.

0 Answers  


What is a prompt box in javascript?

0 Answers  


Categories