There is nothing magical about functions and constructors. All objects in JavaScript are … well, objects. But some objects are more special than the others: namely built-in objects. The difference lies mostly in following aspects:

  1. General treatment of objects. Examples:
    • Numbers and Strings are immutable (⇒ constants). No methods are defined to change them internally — new objects are always produced as the result. While they have some innate methods, you cannot change them, or add new methods. Any attempts to do so will be ignored.
    • null and undefined are special objects. Any attempt to use a method on these objects or define new methods causes an exception.
  2. Applicable operators. JavaScript doesn't allow to (re)define operators, so we stuck with what's available.
    • Numbers have a special way with arithmetic operators: +, -, *, /.
    • Strings have a special way to handle the concatenation operator: +.
    • Functions have a special way to handle the "call" operator: (), and the new operator. The latter has the innate knowledge on how to use the prototype property of the constructor, construct an object with proper internal links to the prototype, and call the constructor function on it setting up this correctly.

If you look into the ECMAScript standard (PDF) you will see that all these "extra" functionality is defined as methods and properties, but many of them are not available to programmers directly. Some of them will be exposed in the new revision of the standard ES3.1 (draft as of 15 Dec 2008: PDF). One property (__proto__) is already exposed in Firefox.

Now we can answer your question directly. Yes, a function object has properties, and we can add/remove them at will:

var fun = function(){/* ... */};
fun.foo = 2;
console.log(fun.foo);  // 2
fun.bar = "Ha!";
console.log(fun.bar);  // Ha!

It really doesn't matter what the function actually does — it never comes to play because we don't call it! Now let's define it:

fun = function(){ this.life = 42; };

By itself it is not a constructor, it is a function that operates on its context. And we can easily provide it:

var context = {ford: "perfect"};

// now let's call our function on our context
fun.call(context);

// it didn't create new object, it modified the context:
console.log(context.ford);           // perfect
console.log(context.life);           // 42
console.log(context instanceof fun); // false

As you can see it added one more property to the already existing object.

In order to use our function as a constructor we have to use the new operator:

var baz = new fun();

// new empty object was created, and fun() was executed on it:
console.log(baz.life);           // 42
console.log(baz instanceof fun); // true

As you can see new made our function a constructor. Following actions were done by new:

  1. New empty object ({}) was created.
  2. Its internal prototype property was set to fun.prototype. In our case it will be an empty object ({}) because we didn't modify it in any way.
  3. fun() was called with this new object as a context.

It is up to our function to modify the new object. Commonly it sets up properties of the object, but it can do whatever it likes.

Fun trivia:

  • Because the constructor is just an object we can calculate it:

    var A = function(val){ this.a = val; };
    var B = function(val){ this.b = val; };
    var C = function(flag){ return flag ? A : B; };
    
    // now let's create an object:
    var x = new (C(true))(42);
    
    // what kind of object is that?
    console.log(x instanceof C); // false
    console.log(x instanceof B); // false
    console.log(x instanceof A); // true
    // it is of A
    
    // let's inspect it
    console.log(x.a); // 42
    console.log(x.b); // undefined
    
    // now let's create another object:
    var y = new (C(false))(33);
    
    // what kind of object is that?
    console.log(y instanceof C); // false
    console.log(y instanceof B); // true
    console.log(y instanceof A); // false
    // it is of B
    
    // let's inspect it
    console.log(y.a); // undefined
    console.log(y.b); // 33
    
    // cool, heh?
    
  • Constructor can return a value overriding the newly created object:

    var A = function(flag){
      if(flag){
        // let's return something completely different
        return {ford: "perfect"};
      }
      // let's modify the object
      this.life = 42;
    };
    
    // now let's create two objects:
    var x = new A(false);
    var y = new A(true);
    
    // let's inspect x
    console.log(x instanceof A); // true
    console.log(x.ford);         // undefined
    console.log(x.life);         // 42
    
    // let's inspect y
    console.log(y instanceof A); // false
    console.log(y.ford);         // perfect
    console.log(y.life);         // undefined
    

    As you can see x is of A with the prototype and all, while y is our "naked" object we returned from the constructor.

Answer from Eugene Lazutkin on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Function › Function
Function() constructor - JavaScript | MDN
January 21, 2026 - The Function() constructor creates Function objects. Calling the constructor directly can create functions dynamically, but suffers from security and similar (but far less significant) performance issues as eval(). However, unlike eval (which may have access to the local scope), the Function ...
🌐
W3Schools
w3schools.com › js › js_object_constructors.asp
JavaScript Constructors
In the constructor function, this has no value. The value of this will become the new object when a new object is created. JavaScript Object this.
🌐
W3Schools
w3schools.com › js › js_classes.asp
JavaScript Classes
It is a template for JavaScript objects. When you have a class, you can use the class to create objects: const myCar1 = new Car("Ford", 2014); const myCar2 = new Car("Audi", 2019); ... The example above uses the Car class to create two Car objects.
Top answer
1 of 8
14

There is nothing magical about functions and constructors. All objects in JavaScript are … well, objects. But some objects are more special than the others: namely built-in objects. The difference lies mostly in following aspects:

  1. General treatment of objects. Examples:
    • Numbers and Strings are immutable (⇒ constants). No methods are defined to change them internally — new objects are always produced as the result. While they have some innate methods, you cannot change them, or add new methods. Any attempts to do so will be ignored.
    • null and undefined are special objects. Any attempt to use a method on these objects or define new methods causes an exception.
  2. Applicable operators. JavaScript doesn't allow to (re)define operators, so we stuck with what's available.
    • Numbers have a special way with arithmetic operators: +, -, *, /.
    • Strings have a special way to handle the concatenation operator: +.
    • Functions have a special way to handle the "call" operator: (), and the new operator. The latter has the innate knowledge on how to use the prototype property of the constructor, construct an object with proper internal links to the prototype, and call the constructor function on it setting up this correctly.

If you look into the ECMAScript standard (PDF) you will see that all these "extra" functionality is defined as methods and properties, but many of them are not available to programmers directly. Some of them will be exposed in the new revision of the standard ES3.1 (draft as of 15 Dec 2008: PDF). One property (__proto__) is already exposed in Firefox.

Now we can answer your question directly. Yes, a function object has properties, and we can add/remove them at will:

var fun = function(){/* ... */};
fun.foo = 2;
console.log(fun.foo);  // 2
fun.bar = "Ha!";
console.log(fun.bar);  // Ha!

It really doesn't matter what the function actually does — it never comes to play because we don't call it! Now let's define it:

fun = function(){ this.life = 42; };

By itself it is not a constructor, it is a function that operates on its context. And we can easily provide it:

var context = {ford: "perfect"};

// now let's call our function on our context
fun.call(context);

// it didn't create new object, it modified the context:
console.log(context.ford);           // perfect
console.log(context.life);           // 42
console.log(context instanceof fun); // false

As you can see it added one more property to the already existing object.

In order to use our function as a constructor we have to use the new operator:

var baz = new fun();

// new empty object was created, and fun() was executed on it:
console.log(baz.life);           // 42
console.log(baz instanceof fun); // true

As you can see new made our function a constructor. Following actions were done by new:

  1. New empty object ({}) was created.
  2. Its internal prototype property was set to fun.prototype. In our case it will be an empty object ({}) because we didn't modify it in any way.
  3. fun() was called with this new object as a context.

It is up to our function to modify the new object. Commonly it sets up properties of the object, but it can do whatever it likes.

Fun trivia:

  • Because the constructor is just an object we can calculate it:

    var A = function(val){ this.a = val; };
    var B = function(val){ this.b = val; };
    var C = function(flag){ return flag ? A : B; };
    
    // now let's create an object:
    var x = new (C(true))(42);
    
    // what kind of object is that?
    console.log(x instanceof C); // false
    console.log(x instanceof B); // false
    console.log(x instanceof A); // true
    // it is of A
    
    // let's inspect it
    console.log(x.a); // 42
    console.log(x.b); // undefined
    
    // now let's create another object:
    var y = new (C(false))(33);
    
    // what kind of object is that?
    console.log(y instanceof C); // false
    console.log(y instanceof B); // true
    console.log(y instanceof A); // false
    // it is of B
    
    // let's inspect it
    console.log(y.a); // undefined
    console.log(y.b); // 33
    
    // cool, heh?
    
  • Constructor can return a value overriding the newly created object:

    var A = function(flag){
      if(flag){
        // let's return something completely different
        return {ford: "perfect"};
      }
      // let's modify the object
      this.life = 42;
    };
    
    // now let's create two objects:
    var x = new A(false);
    var y = new A(true);
    
    // let's inspect x
    console.log(x instanceof A); // true
    console.log(x.ford);         // undefined
    console.log(x.life);         // 42
    
    // let's inspect y
    console.log(y instanceof A); // false
    console.log(y.ford);         // perfect
    console.log(y.life);         // undefined
    

    As you can see x is of A with the prototype and all, while y is our "naked" object we returned from the constructor.

2 of 8
12

Your understanding is wrong:

myFunction().myProperty; // myFunction has no properties

The reason it does not work is because ".myProperty" is applied to the returned value of "myFunction()", not to the object "myFunction". To wit:

$ js
js> function a() { this.b=1;return {b: 2};}
js> a().b
2
js> 

Remember, "()" is an operator. "myFunction" is not the same as "myFunction()". You don't need a "return" when instanciang with new:

js> function a() { this.b=1;}
js> d = new a();
[object Object]
js> d.b;
1
🌐
Playwright
playwright.dev › fixtures
Fixtures | Playwright
import type { Page, Locator } from '@playwright/test'; export class TodoPage { private readonly inputBox: Locator; private readonly todoItems: Locator; constructor(public readonly page: Page) { this.inputBox = this.page.locator('input.new-todo'); this.todoItems = this.page.getByTestId('todo-item'); } async goto() { await this.page.goto('https://demo.playwright.dev/todomvc/'); } async addToDo(text: string) { await this.inputBox.fill(text); await this.inputBox.press('Enter'); } async remove(text: string) { const todo = this.todoItems.filter({ hasText: text }); await todo.hover(); await todo.getByLabel('Delete').click(); } async removeAll() { while ((await this.todoItems.count()) > 0) { await this.todoItems.first().hover(); await this.todoItems.getByLabel('Delete').first().click(); } } }
🌐
Scaler
scaler.com › home › topics › javascript › javascript constructor function
JavaScript Constructor Function - Scaler Topics
October 26, 2023 - Constructors in Javascript are a special kind of function used to create and instantiate objects, especially when multiple objects of the same kind need to be created. A constructor defines the object properties and methods.
🌐
SheCodes
shecodes.io › athena › 97552-what-is-a-constructor-function-in-javascript-and-how-to-use-it
[JavaScript] - What is a constructor function in JavaScript and how to use it?
Learn about the concept of a constructor function in JavaScript and how it is used to create objects with initial values and properties.
Find elsewhere
🌐
Mongoose
mongoosejs.com › docs › guide.html
Mongoose v9.4.1: Schemas
Schemas have a few configurable options which can be passed to the constructor or to the set method: new Schema({ /* ... */ }, options); // or const schema = new Schema({ /* ... */ }); schema.set(option, value); ... By default, Mongoose's init() function creates all the indexes defined in your model's schema by calling Model.createIndexes() after you successfully connect to MongoDB.
🌐
Axios
axios-http.com › docs › instance
The Axios Instance | Axios Docs
In addition to using convenience methods like instance.get() or instance.post(), you can also call an Axios instance directly with a config object. This is functionally equivalent to axios(config), and is particularly useful when retrying a request using the original configuration.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › functions-in-javascript
Functions in JavaScript - GeeksforGeeks
JavaScript Basics · Introduction4 min read · Variables5 min read · Operators4 min read · Control Statements4 min read · Array & String · Arrays7 min read · Array Methods7 min read · String5 min read · String Methods9 min read · Function & Object · Functions4 min read · Function Expression3 min read · Function Overloading4 min read · Objects4 min read · Constructors4 min read ·
Published   January 22, 2026
🌐
Kevin Chisholm
blog.kevinchisholm.com › javascript › the-javascript-this-keyword-deep-dive-constructor-functions
The JavaScript “this” Keyword Deep Dive: Constructor Functions | Kevin Chisholm - Blog
February 10, 2021 - We’ve also created a constructor function named “Foo”. When we instantiate Foo, we assign that instantiation to the variable: “bar”. In other words, the variable “bar” becomes an instance of “Foo”. This is a very important point. When you instantiate a JavaScript constructor function, the JavaScript “this” keyword refers to the instance of the constructor.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Classes › constructor
constructor - JavaScript | MDN
The constructor method is a special method of a class for creating and initializing an object instance of that class.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-function-constructor
JavaScript Function() Constructor - GeeksforGeeks
July 23, 2025 - The JavaScript Function() constructor is used to create new function objects dynamically. By using the Function() constructor with the new operator, developers can define functions on the fly, passing the function body as a string.
🌐
Medium
medium.com › @halfcircassian › constructor-functions-in-javascript-101-a7123efbc0b6
Constructor Functions in JavaScript 101 | by Sıla Özeren | Medium
October 30, 2024 - A constructor function is a special type of function in JavaScript that’s used to create and initialize new objects. Unlike regular functions, which just perform a set of actions, constructor functions are designed to set up an object’s ...
🌐
Programiz
programiz.com › javascript › constructor-function
JavaScript Constructor Function (with Examples)
In JavaScript, a constructor function is used to create and initialize objects.
🌐
Rollbar
rollbar.com › home › javascript constructors: what you need to know
JavaScript Constructors: What You Need to Know | Rollbar
December 12, 2022 - JavaScript constructors are special functions that creates and initializes an object instance of a class when created using the "new" keyword.
🌐
DEV Community
dev.to › emmanuelonah › should-we-break-the-hood-behind-the-class-base-program-the-syntactic-sugar-trying-to-make-our-functional-base-look-dump-331n
Function Constructor in Javascript - DEV
August 29, 2020 - Things to learn from this article: ... of the whole implementation. What is a constructor? a constructor is just a normal javascript function with two main conventions: a....
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › intellisense
IntelliSense
November 3, 2021 - When applicable, a language service surfaces the underlying types in the quick info and method signatures. In the previous screenshot, you can see several any types. Because JavaScript is dynamic and doesn't need or enforce types, any suggests that the variable can be of any type.
🌐
NestJS
docs.nestjs.com › providers
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).