Why use New?


#1

26: Array of Objects

My Code:

function Person(name, age) {
this.name = name;
this.age = age;
console.log (this.name +" "+this.age);
}
var family = new Array();
family[0] = new this.Person("John", 25);
family[1] = new this.Person("Tom", 35);

I understand why we use new to create a new array:

var family = new Array();

But while assigning values into this 'new' array, why should i use'new'?

family[0] = new this.Person("John", 25);

In this example, for assigning values to a an array element [0], why are we are using 'new'?


#2

@sureshdev,

A good article
== discussions / opinions ==
http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript

== the book ==
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new


#3

@leonhard.wettengmx.n
I understood the reasons.
As always thanks a lot!
AND THANK YOU FOR SHARING YOUR GIFT OF KNOWLEDGE WITH ALL OF US!