Constructor Functions
File Location
javascript-library
└── 0-PreWork
└── 1-Fundamentals
└── 11-Objects
01-properties.js
02-enumeration.js
03-initializers.js
04-constructor-function.js <----You will be working in this file.function Person(name, age){
//Note that the argument aligns with the RHS(Right Hand Side)
//The variable created will take the place of this
this.name = name;
this.age = age;
}
var paul = new Person("Paul", 41);
console.log(paul.name);
var sophie = new Person("Sophie", 5);
var ava = new Person("Ava", 15);
console.log(sophie.name);Practice
Bonus Challenge
Last updated