Understanding the new Keyword in JavaScript
When you see the new keyword in JavaScript, it usually appears with functions.
At first, it feels confusing.
But the idea is simple:
new is used to create objects from a function.
It takes a function and turns it into a blueprint for creating objects.
What the new Keyword Does
The new keyword creates a new object and connects it with a constructor function.
Example:
function Person(name, age) {
this.name = name
this.age = age
}
let user1 = new Person("Ishan", 21)
console.log(user1)
Here:
Personis a constructor functionnew Person()creates a new object
Constructor Functions
A constructor function is just a normal function, but it is used to create objects.
By convention, constructor names start with a capital letter.
function Car(brand) {
this.brand = brand
}
let car1 = new Car("Toyota")
The this keyword refers to the new object being created.
Object Creation Process (Step by Step)
When you use new, JavaScript does multiple things behind the scenes.
Example:
let user = new Person("Ishan", 21)
What actually happens:
A new empty object is created
thisis set to that objectProperties are assigned (
name,age)The object is returned
So new is not just creating — it’s doing a full process.
How new Links Prototypes
Every object in JavaScript has a prototype.
When you use new, the created object is linked to the constructor’s prototype.
Example:
function Animal(name) {
this.name = name
}
Animal.prototype.sound = function () {
console.log("Some sound")
}
let dog = new Animal("Dog")
dog.sound()
Here:
doggets access tosound()not because it’s inside the object
but because of prototype linking
Instances Created from Constructors
Every time you use new, a new instance is created.
let user1 = new Person("A", 20)
let user2 = new Person("B", 25)
Each object:
has its own data
shares common behavior (via prototype)
So constructors help create multiple objects easily.
How to Think About It
Instead of thinking about syntax, think like this:
constructor = blueprint
new = creates object
object = instance
One Line Summary
new creates an object from a function and sets up its structure.
Conclusion
The new keyword is used to create objects from constructor functions.
It not only creates the object but also sets up this, assigns values, and links prototypes.
Understanding this helps you see how JavaScript builds objects behind the scenes.