Logo
HTMLCSSJavaScriptReactjsnewContactUpdates

Get started today

HTMLCSSJavaScriptReactjsnewContactUpdates

Tools

Resume BuilderQR GeneratorVS Code Editor

Connect

GitHubWhatsApp Channel
call apply bind
this keyword

Javascript Constructor Function

By Saket Bhatnagar•June 15, 2025•Beginner to Intermediate

Table of Contents

  1. constructor function

constructor function

  1. 1A function which is used to create an object is known as constructor function.
  2. 2A constructor function behaves like blueprint or template for object , and there is no need to write code again and again
  3. 3 It helps us to create multiple objects of same type.
  4. 4Syntax : function identifier (parameter,...){ }
  5. 5 If the function is designed to use as a constructor than name of function should be upper camel case.
  6. 6 The list of parameter provided to the function will be treated as keys/properties of the object.
  7. 7 The argument pass when function is called will be value of object.
  8. 8 We can copy the values into the keys of the object from parameter using this keyword.
  9. 9 We can create a object using the constructor function with the help of new keyword.
  10. 10To create constructor function we will not use arrow function because they does not have 'this' keyword .
  11. 11Synatx : let variable = new function_name(arguments)
  12. 12

    Example :

    1function Car(model,color,engine) {
    2this.model = model;
    3this.color = color;
    4this.engine = engine;
    5}
    6
    7let car1 = new Car(1021,"red","V8");
    8console.log(car1);
    9// { model:1021,color:"red",engine:"V8" }

Share this article

Last updated: July 15, 2025

Join Our Community

Login to Join

© 2025 Saket Bhatnagar. All rights reserved.

    ☕