- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Object Constructors
JavaScript Objects
JavaScript Object Constructors
A JavaScript constructor function builds many objects with the same shape.
Writing out the same object by hand ten times is repetitive and easy to get wrong.
A constructor is a template you call with the new keyword.
Example
Example
javascript
function Person(name) {
this.name = name;
}
const ada = new Person("Ada");
console.log(ada.name);The output is Ada.
