# [JavaScript] Object-Oriented Programming (OOP) with JavaScript : Constructor Functions and the 'new' Operator

```
const Person = function (firstName, birthYear) {  // begin with capitalization...
  // Instance properties
  this.firstName = firstName;
  this.birthYear = birthYear;

  // Never create a method inside constructor function. (terrible performance)
  //   this.calcAge = function () {
  //     console.log(2037 - this.birthYear);
  //   };
};

const jonas = new Person('Jonas, 1991'); // for constructor function need 'new' operator always.
console.log(jonas);

// Progress of constructor function
// 1. New {} is created
// 2. function is called, this = {}
// 3. {} linked to prototype
// 4. function automatically return {}.

const matilda = new Person('Matilda', 2017);
const jack = new Person('Jack', 1975);
const jayden = new Person('Jayden', 1981);
console.log(matilda, jack, jayden);

const jay = 'Jay';

console.log(jonas instanceof Person); // create instance.
console.log(jay instanceof Person);
```

![constructor function and new operator.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1658504894565/itYHUdBR_.PNG align="left")

