<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Understanding the new Keyword in JavaScript: How Objects Are Created Behind the Scenes]]></title><description><![CDATA[Understanding the new Keyword in JavaScript: How Objects Are Created Behind the Scenes]]></description><link>https://understandingthenewkeywordinjavascripthowobjects.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 23:22:51 GMT</lastBuildDate><atom:link href="https://understandingthenewkeywordinjavascripthowobjects.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding the new Keyword in JavaScript: How Objects Are Created Behind the Scenes]]></title><description><![CDATA[Ever wondered what new actually does?
You’ve probably seen code like this:
const user = new User("Adarsh", 21);

It looks simple.
But behind the scenes, JavaScript is doing multiple steps automaticall]]></description><link>https://understandingthenewkeywordinjavascripthowobjects.hashnode.dev/understanding-the-new-keyword-in-javascript-how-objects-are-created-behind-the-scenes</link><guid isPermaLink="true">https://understandingthenewkeywordinjavascripthowobjects.hashnode.dev/understanding-the-new-keyword-in-javascript-how-objects-are-created-behind-the-scenes</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Adarsh Pandey]]></dc:creator><pubDate>Tue, 14 Apr 2026 15:28:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/678cea9058ec54fd2f9de6b8/d9b2160f-d54c-45cf-baa7-6136d4a1b6d8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Ever wondered what <code>new</code> actually does?</h2>
<p>You’ve probably seen code like this:</p>
<pre><code class="language-javascript">const user = new User("Adarsh", 21);
</code></pre>
<p>It looks simple.</p>
<p>But behind the scenes, JavaScript is doing <strong>multiple steps automatically</strong>.</p>
<p>So the real question is:</p>
<blockquote>
<p><em>What does</em> <code>new</code> <em>actually do?</em></p>
</blockquote>
<p>Let’s break it down in the simplest way possible.</p>
<hr />
<h2>Why do we need <code>new</code>?</h2>
<p>Imagine you want to create multiple similar objects:</p>
<pre><code class="language-javascript">const user1 = { name: "Adarsh", age: 21 };
const user2 = { name: "Rahul", age: 22 };
</code></pre>
<p>This works… but:</p>
<ul>
<li><p>Repetitive ❌  </p>
</li>
<li><p>Not scalable ❌</p>
</li>
</ul>
<p>We need a <strong>blueprint</strong>.</p>
<hr />
<h2>🏗️ Constructor functions</h2>
<p>A <strong>constructor function</strong> is like a blueprint for creating objects.</p>
<pre><code class="language-javascript">function User(name, age) {
  this.name = name;
  this.age = age;
}
</code></pre>
<p>Now we can create objects easily:</p>
<pre><code class="language-javascript">const user1 = new User("Adarsh", 21);
const user2 = new User("Rahul", 22);
</code></pre>
<hr />
<h2>Real-life analogy</h2>
<p>Think of a <strong>factory</strong> :</p>
<ul>
<li><p>Constructor function → factory design  </p>
</li>
<li><p><code>new</code> → machine that builds products  </p>
</li>
<li><p>Object → final product</p>
</li>
</ul>
<hr />
<h2>🔍 What does <code>new</code> actually do?</h2>
<p>When you write:</p>
<pre><code class="language-javascript">const user = new User("Adarsh", 21);
</code></pre>
<p>JavaScript secretly does <strong>4 steps</strong>:</p>
<hr />
<h3>1️⃣ Creates a new empty object</h3>
<pre><code class="language-javascript">const user = {};
</code></pre>
<hr />
<h3>2️⃣ Links it to the constructor’s prototype</h3>
<pre><code class="language-javascript">user.__proto__ = User.prototype;
</code></pre>
<p>This allows the object to access shared methods.</p>
<hr />
<h3>3️⃣ Calls the constructor function</h3>
<pre><code class="language-javascript">User.call(user, "Adarsh", 21);
</code></pre>
<p><code>this</code> now refers to the new object</p>
<hr />
<h3>4️⃣ Returns the object</h3>
<pre><code class="language-javascript">return user;
</code></pre>
<h3>Visual flow</h3>
<pre><code class="language-javascript">User Constructor
      ↓
 new keyword used
      ↓
Empty object created {}
      ↓
Linked to prototype
      ↓
Constructor runs (this = object)
      ↓
Object returned
</code></pre>
<h3>Simple example with methods</h3>
<pre><code class="language-javascript">function Car(brand) {
  this.brand = brand;
}

Car.prototype.drive = function () {
  console.log(`${this.brand} is driving`);
};

const car1 = new Car("BMW");
car1.drive(); // BMW is driving
</code></pre>
<h2>What’s happening here?</h2>
<ul>
<li><p><code>car1</code> gets <code>brand</code> from constructor</p>
</li>
<li><p><code>drive()</code> comes from <strong>prototype</strong></p>
</li>
</ul>
<h2>How <code>new</code> links prototypes</h2>
<p>This is the most important part.</p>
<pre><code class="language-javascript">car1.__proto__ === Car.prototype // true
</code></pre>
<p>That’s why <code>car1</code> can use <code>drive()</code></p>
<hr />
<h2>Analogy for prototype</h2>
<p>Think of it like:</p>
<ul>
<li><p>Prototype = shared toolbox  </p>
</li>
<li><p>Every object gets access to it</p>
</li>
</ul>
<p>Instead of duplicating methods, they <strong>share one copy</strong></p>
<h2>nstances created from constructors</h2>
<p>Each time you use <code>new</code>, you get a <strong>new instance</strong>.</p>
<pre><code class="language-javascript">const user1 = new User("Adarsh", 21);
const user2 = new User("Rahul", 22);
</code></pre>
<ul>
<li><p>Different objects  </p>
</li>
<li><p>Same structure  </p>
</li>
<li><p>  Shared methods via prototype</p>
</li>
</ul>
<hr />
<h2>Why this is powerful</h2>
<ul>
<li><p>Saves memory  </p>
</li>
<li><p>Keeps code organized  </p>
</li>
<li><p>Makes object creation scalable</p>
</li>
</ul>
<h2>What happens without <code>new</code>?</h2>
<pre><code class="language-javascript">const user = User("Adarsh", 21);
</code></pre>
<p>Problems:</p>
<ul>
<li><p><code>this</code> may point to global object  </p>
</li>
<li><p>No new object created</p>
</li>
</ul>
<p>Always use <code>new</code> with constructor functions</p>
<h2>Modern alternative (just a note)</h2>
<p>Today, we mostly use <strong>classes</strong>, but internally they still use <code>new</code>.</p>
<pre><code class="language-javascript">class User {
  constructor(name) {
    this.name = name;
  }
}

const user = new User("Adarsh");
</code></pre>
<p>👉 <code>new</code> is still doing the same work.</p>
<hr />
<h2>🎯 Key takeaway</h2>
<blockquote>
<p>The <code>new</code> keyword creates a new object, links it to a prototype, runs the constructor, and returns the object.</p>
</blockquote>
<hr />
<h2>🏁 Final thoughts</h2>
<p>At first, <code>new</code> looks like just a keyword.</p>
<p>But once you understand it:</p>
<ul>
<li><p>You understand how JavaScript creates objects</p>
</li>
<li><p>You understand prototypes better</p>
</li>
<li><p>You write cleaner, scalable code</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>