The main differences: syntax: class syntax is cleaner, keeping everything together under a single class block and handling a lot of the boilerplate for you. safety: Code run in class definitions is always in strict mode. You also can't accidentally call a class constructor as a function or an error will be thrown. built-ins support/initialization: class initialization starts at the base class and works down to the derived class. This allows base classes to define the this (the new instance) which in turn allows class syntax to correctly support extending built-ins like Array. Alternatively, function constructors create the instance in the derived class and pass it up to the base for initialization so a base class has no influence over what this is. feature support: class syntax can support features that function constructors don't, in particular private members . The upcoming support for decorators is also only for class syntax. Some other smaller differences: When using toString() class functions will always use the class syntax (though shouldn't be too surprising since toString() defaults to showing the source of the function) The prototype on a class-defined constructor is defined as read-only. whereas function prototype properties are not function declaration definitions are hoisted, class declaration definitions are not Being in a class block allows a local name binding for the class (assuming its named) to be available to all members defined within the class block Answer from senocular on reddit.com
🌐
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.
🌐
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.
🌐
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 ...
🌐
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 ...
🌐
Codecademy
codecademy.com › docs › javascript › constructors
JavaScript | Constructors | Codecademy
June 26, 2024 - To use a constructor function to create objects, simply define a JavaScript function with any number of arguments. Inside the function, the keyword this is used as a placeholder for the object being created.
🌐
Programiz
programiz.com › javascript › constructor-function
JavaScript Constructor Function (with Examples)
In JavaScript, a constructor function is used to create and initialize objects.
Find elsewhere
🌐
Medium
medium.com › javascript-scene › javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e
JavaScript Factory Functions vs Constructor Functions vs Classes | by Eric Elliott | JavaScript Scene | Medium
August 24, 2021 - Each of these strategies stores methods on a shared prototype, and optionally supports private data via constructor function closures. In other words, they have mostly the same features, and could mostly be used interchangeably. In JavaScript, any function can return a new object.
🌐
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.
🌐
Reddit
reddit.com › r/learnjavascript › what is the difference between "class" and "constructor function" in js? i tried looking up on yt but found nothing relevant atlest for me.
r/learnjavascript on Reddit: What is the difference between "class" and "constructor function" in js? I tried looking up on YT but found nothing relevant atlest for me.
May 16, 2022 -

So I am learning NodeJs and while creating a costum module which stores user data I created a constructor function in user.js

function User(name,age){
this.name = name;
this.age = age;
}

and in app.js I did

const User = require(//Path);

const user1 = new User("Adam",20);
console.log(user1.name);

but my consfusion begans when I used class in user.js like

class User{
    constructor(name,age){
        this.name = name;
        this.age = age;
    }
}

but the code in the app.js remained similar with no errors.

So what is the point of classes in javasript? And how are they different form contructor functions.

Top answer
1 of 7
15
The main differences: syntax: class syntax is cleaner, keeping everything together under a single class block and handling a lot of the boilerplate for you. safety: Code run in class definitions is always in strict mode. You also can't accidentally call a class constructor as a function or an error will be thrown. built-ins support/initialization: class initialization starts at the base class and works down to the derived class. This allows base classes to define the this (the new instance) which in turn allows class syntax to correctly support extending built-ins like Array. Alternatively, function constructors create the instance in the derived class and pass it up to the base for initialization so a base class has no influence over what this is. feature support: class syntax can support features that function constructors don't, in particular private members . The upcoming support for decorators is also only for class syntax. Some other smaller differences: When using toString() class functions will always use the class syntax (though shouldn't be too surprising since toString() defaults to showing the source of the function) The prototype on a class-defined constructor is defined as read-only. whereas function prototype properties are not function declaration definitions are hoisted, class declaration definitions are not Being in a class block allows a local name binding for the class (assuming its named) to be available to all members defined within the class block
2 of 7
15
In most practical situations, there is little to no difference. Classes in Javascript are what is called syntactic sugar which means it's just a different way or representing the same thing.
🌐
Vojtechruzicka
vojtechruzicka.com › javascript-constructor-functions-and-new-operator
Javascript constructor functions and new operator | Vojtech Ruzicka's Programming Blog
February 2, 2018 - Constructors are guaranteed to return a new instance of the class, performing all the required initialization. Constructors can be invoked only using the new keyword and the new keyword can be used only to invoke constructors. In javascript, the situation is unfortunately not so strict. ... So, calling function not designed as constructor will not result in an error.
🌐
GitConnected
levelup.gitconnected.com › constructor-functions-vs-class-definitions-in-javascript-who-wins-1ec08efb2591
Constructor Functions vs. Class Definitions in JavaScript — Who WINS? | by Ebo Jackson | Level Up Coding
November 17, 2024 - Use Classes for New Projects: If you’re starting a new project or working in an environment that supports ES6, use classes. The syntax is cleaner, more readable, and aligns with modern JavaScript practices. Consider Constructor Functions for Compatibility: If you need to support older JavaScript environments, constructor functions with prototypes may be necessary.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-object-constructors
JavaScript Object Constructors - GeeksforGeeks
January 20, 2026 - A constructor function in JavaScript is a special function used with the new keyword to create and initialize objects of a specific type, allowing multiple instances with similar structure but unique properties.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Constructor, operator "new"
The “capital letter first” is a common agreement, to make it clear that a function is to be run with new. ... If we have many lines of code all about creation of a single complex object, we can wrap them in an immediately called constructor function, like this:
🌐
Medium
medium.com › @hridoymahmud › understanding-javascript-constructors-function-vs-class-63d140a44288
Understanding JavaScript Constructors: Function vs. Class | by Mahmudur Rahman | Medium
July 11, 2024 - Understanding JavaScript Constructors: Function vs. Class In the world of JavaScript, creating and initializing objects is a fundamental task. Two primary ways to achieve this are through constructor …
🌐
Educative
educative.io › answers › what-is-the-constructor-function-in-javascript
What is the constructor function in Javascript?
They are the templates with which to create multiple objects with the same properties and methods but with different values (assigned initially). In this shot, we are going to talk about constructors in a JavaScript function and the different things associated with them.
🌐
Playcode
playcode.io › javascript › constructor
JavaScript Constructor Functions: Create Objects with new | Playcode
Learn JavaScript constructor functions: create objects with the new keyword, understand how constructors work, and compare with factory functions and ES6 classes.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › js-constructor-method
JavaScript Constructor Method - GeeksforGeeks
A constructor is a special function used to create and initialize objects, defined using the function keyword or class syntax. The new keyword triggers the constructor, creating a new object and setting this to refer to it.
Published   2 weeks ago
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_function_constructor.htm
JavaScript - Function() Constructor
The JavaScript Function() constructor can dynamically create a function object at the run time. The functions created using Function() constructor have global scope only.