From the course: JavaScript on the Go: Objects

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Define an object using a constructor function

Define an object using a constructor function - JavaScript Tutorial

From the course: JavaScript on the Go: Objects

Define an object using a constructor function

- [Instructor] In JavaScript there are two ways to create and store data in an object. The object literal is the simplest and most common way to create objects. The other way is using a constructor function. So now let's explore what constructors are and how developers use them to describe an object structure and behavior with just a single function. That way the next time you come across the term constructor or constructor function, you'll be more equipped with the basics of how they're used. A constructor is a special function that you call using JavaScript's new keyword. Think of a constructor function as a template for creating one or multiple objects with similar properties and behavior. When you call a constructor it creates and initializes a new object. And there are two main ways to create objects with constructor functions. One is with JavaScripts built in object constructor and the other is with a custom…

Contents