---
title: "How to use the arrow function as a constructor function in JavaScript?"  
description: "How to use the arrow function as a constructor function in JavaScript?"  
author: "Utpal Vishwas"  
published: 2023-10-08  
updated: 2023-10-09  
canonical: https://www.mindstick.com/forum/160059/how-to-use-the-arrow-function-as-a-constructor-function-in-javascript  
category: "javascript"  
tags: ["javascript", "arrow function"]  
reading_time: 2 minutes  

---

# How to use the arrow function as a constructor function in JavaScript?

How to use the [arrow function](https://www.mindstick.com/forum/160054/how-to-pass-parameter-values-in-javascript-arrow-function) as a constructor function in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

[Arrow](https://answers.mindstick.com/qa/95602/which-country-test-flighted-arrow-3-anti-ballistic-missile-system-and-its-interceptors) functions in JavaScript are not suitable for use as constructor functions. Arrow functions are designed for short, concise [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) expressions and do not have their own **this** binding. Instead, they lexically inherit the **this** value from the surrounding context. This means they cannot be used to create new objects with their own properties and methods like constructor functions created with the **function** keyword.

To create constructor functions in JavaScript, you should use the **function** keyword. Here's an example of a constructor function and how to use it:

```plaintext
function Person(name, age) {
  this.name = name;
  this.age = age;
}

Person.prototype.sayHello = function() {
  console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
};

const person1 = new Person("Alice", 25);
const person2 = new Person("Bob", 30);

person1.sayHello(); // Outputs: "Hello, my name is Alice and I am 25 years old."
person2.sayHello(); // Outputs: "Hello, my name is Bob and I am 30 years old."
```

In this example:

- **Person** is a constructor function created with the **function** keyword.
- It takes **name** and **age** as parameters and assigns them as properties of the newly created object.
- **Person.prototype.sayHello** is used to add a method to all instances created from the **Person** constructor.

You should stick to using the **function** keyword for constructor functions when you need to create instances with their own properties and methods. Arrow functions are not appropriate for this purpose.


---

Original Source: https://www.mindstick.com/forum/160059/how-to-use-the-arrow-function-as-a-constructor-function-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
