A constructor function in JavaScript is a special type of function used to create and initialize objects, acting as a blueprint for creating multiple instances of similar objects.
Key characteristics of a constructor function include being called with the new keyword, used for initializing object properties, and conventionally named with a capitalized first letter.
Inefficient way of adding methods is defining inside the constructor function, leading to new function creation for every instance, while the efficient way is using prototype for shared methods.
By using .prototype for methods, memory usage is reduced, and JavaScript looks up methods through the prototype chain when calling them, allowing shared use among instances.
The constructor property in JavaScript ensures that instances can identify their constructor function, and instanceof is used to check if an object was created by a specific constructor.
ES6 introduced class syntax as syntactic sugar over constructor functions, making syntax more readable and automatically adding methods to the prototype.
When using new Circle(), an empty object is created internally, the prototype is set, properties or methods using this are assigned to the new object, and the new object is returned.
Instances can override prototype methods if needed, providing flexibility in method definitions, and Object.create() allows manual prototype setting without constructor functions.
Difference between constructor function and regular function include usage with new, purpose of creating objects, naming convention, prototype linkage, and return behavior.
Capitalization is not mandatory for constructor functions, but it is a best practice to use PascalCase to indicate that the function should be called with new, helping distinguish them from regular functions.