The new Keyword in JavaScript

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
In this article we'll learn about another magical keyword of JavaScript, the new keyword. The new keyword is used to create objects from constructor functions. Instead of manually creating an object every time, new helps automate the process and gives you a clean way to create multiple similar objects.
At a high level, when you use new, JavaScript does a few things behind the scenes:
creates a brand new empty object
links that object to a prototype
runs the constructor function with this pointing to that new object
returns the object
This is why new is so powerful — it bundles multiple steps into one simple line.
A constructor function is just a normal function, but by convention it starts with a capital letter and is meant to be used with new.
Example:
function User(name, age) {
this.name = name;
this.age = age;
}
This function doesn’t return anything explicitly, but when used with new, it will create and return an object.
Let’s say we do this:
const user1 = new User("Alex", 25);
Here’s what actually happens step by step:
{}
It sets the prototype of this object to User.prototype
It calls the constructor:
User.call(newObject, "Alex", 25);
So inside the function:
this.name = "Alex";
this.age = 25;
So user1 becomes:
{
name: "Alex",
age: 25
}
new links prototypesThis is where things get interesting.
Every function in JavaScript has a prototype property. When you use new, the created object is internally linked to that prototype.
User.prototype.greet = function () {
console.log("Hello " + this.name);
};
Now:
const user1 = new User("Alex", 25);
user1.greet();
Even though greet is not inside the object itself, JavaScript looks up the prototype chain and finds it.
So the link looks like this:
user1 -> User.prototype -> Object.prototype
This is called the prototype chain.
Each time we use new, we create a new instance.
const user1 = new User("Alexa", 25);
const user2 = new User("Sam", 30);
Both are separate objects:
user1 !== user2
But they share the same prototype:
user1.__proto__ === user2.__proto__
This is efficient because methods are not duplicated for every object -- they live in one place (the prototype).
The new keyword is basically a shortcut for creating objects in a structured way. It handles object creation, sets up the prototype chain, binds this, and returns the object automatically. Constructor functions define the blueprint, and each call with new creates a new instance that follows that blueprint while sharing common behaviour through prototypes.