The new Keyword in JavaScript
What the new keyword does?
When you use new with a function, JavaScript performs a series of internal steps:
Creates a new empty object
Links that object to a prototype
Binds
thisto the new objectExecutes the constructor function
Returns the object (unless explicitly overridden)
lets try to create object using new keyword
Object Creation Process
function User(name, email) {
this.name = name;
this.email = email;
}
const user1 = new User("Krish", "krish@example.com");
Internal process
const obj = {};
obj.__proto__ = User.prototype;
User.call(obj, "Krish", "krish@example.com");
return obj;
life is simpler than before.
How new Links Prototypes?
Every function in JavaScript has a prototype property.
When using new:
- The created object’s internal
[[Prototype]]is set to the constructor’sprototype
Which we just saw from above code.
Instances Created from Constructors
Objects created using new are called instances.
const user2 = new User("Amit", "amit@example.com");
console.log(user2 instanceof User); // true
Each instance:
Has its own properties
Shares methods via the prototype

