<?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[The new Keyword in JavaScript]]></title><description><![CDATA[The new Keyword in JavaScript]]></description><link>https://the-new-keyword-in-javascript-by-koushik.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/69371c590b8af498352a6399/02dfad10-7b97-4e3e-8fb3-0b05b47377ec.jpg</url><title>The new Keyword in JavaScript</title><link>https://the-new-keyword-in-javascript-by-koushik.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 19 Jun 2026 09:22:12 GMT</lastBuildDate><atom:link href="https://the-new-keyword-in-javascript-by-koushik.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The new Keyword in JavaScript]]></title><description><![CDATA[In JavaScript the new keywords comes in very few times. When ever you deal with Oops in your codebase, new keyword comes in. But just use this with no proper logic is not fair. So let's understand thi]]></description><link>https://the-new-keyword-in-javascript-by-koushik.hashnode.dev/new-keyword-in-javascript</link><guid isPermaLink="true">https://the-new-keyword-in-javascript-by-koushik.hashnode.dev/new-keyword-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Objects]]></category><category><![CDATA[prototype]]></category><category><![CDATA[Blogging]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Koushik Karmakar]]></dc:creator><pubDate>Mon, 13 Apr 2026 17:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69371c590b8af498352a6399/767cf64d-2136-4a32-a943-76ccf499651d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In JavaScript the <code>new</code> keywords comes in very few times. When ever you deal with <code>Oops</code> in your codebase, <code>new</code> keyword comes in. But just use this with no proper logic is not fair. So let's understand this with example.</p>
<hr />
<h2>A) What the <code>new</code> keyword does?</h2>
<p>The <code>new</code> operator is used to create an instance of an object which has a constructor function. It works with some step, but first understand some related concept:</p>
<ol>
<li><p>What is Constructor Function?</p>
</li>
<li><p>How object creates?</p>
</li>
<li><p>What is __<strong>proto</strong>__ and <strong>.prototype?</strong></p>
</li>
</ol>
<hr />
<h2>B) Constructor functions</h2>
<p>A constructor function in JavaScript is a special function, used to create and initialize objects. Like in JavaScript you can create an object using <code>Constructor Function</code> . See in the example:</p>
<pre><code class="language-typescript">function Car(brand, model) {
  this.brand = brand;
  this.model = model;
}

const car1 = new Car("Toyota", "Corolla");

console.log(car1.brand); // Toyota
</code></pre>
<p>But in ES6, there introduced a new method called, <code>class</code> , by using class you can create as many objects as you want with same style and method, but you can control the output by different parameters. See in the example:</p>
<pre><code class="language-typescript">class Car {
  constructor(brand, model) {
    this.brand = brand;
    this.model = model;
  }

  showDetails() {
    console.log(this.brand + " " + this.model);
  }
}

const car1 = new Car("Toyota", "Corolla");
const car2 = new Car("Honda", "Civic");

car1.showDetails(); // Toyota Corolla
car2.showDetails(); // Honda Civic
</code></pre>
<p>If you understand <code>Class</code> in depth read this article: <a href="https://object-oriented-programming-in-javascript-by-koushik.hashnode.dev">https://object-oriented-programming-in-javascript-by-koushik.hashnode.dev</a></p>
<hr />
<h2><strong>C) Object creation process</strong></h2>
<p>An object in JavaScript is a collection of key-value pairs. These key-value pairs are properties of the object. A property can be an array, a function, an object itself or any primitive data type such as strings or integers.</p>
<h3>1) Class method</h3>
<p>You already know about this method. Let's see other methods.</p>
<h3>2) Object Literal Notation</h3>
<pre><code class="language-typescript">let user1 = {
  name: "Koushik",
  scores: 10,
  increment: function() {
    user1.scores++;
  }
};
</code></pre>
<p>A JavaScript object literal is a list of name-value pairs wrapped in curly braces. In the example above, the object ‘user1’ is created, and the associated data is stored within it.</p>
<h3>3) Object.create() method</h3>
<p>You pass into <code>Object.create</code> an object that you want to inherit from, and it returns a new object that inherits from the object you passed into it.</p>
<pre><code class="language-js">let user2 = Object.create(null);

user2.name = "Koushik";
user2.scores = 10;
user2.increment = function() {
  user2.scores++;
}
</code></pre>
<hr />
<h2>D) What is <code>__proto__</code> and <code>.prototype</code><strong>?</strong></h2>
<p>In JavaScript, <code>.prototype</code> is a property set on constructor functions used to define shared methods/properties for instances that are create from it.</p>
<p>__proto__ or <code>[[Prototype]]</code> is an internal property on actual objects (instances) that points to the prototype object it inherits from.</p>
<img src="https://cdn.hashnode.com/uploads/covers/69371c590b8af498352a6399/8ec3752e-6e94-4472-b4b0-293650423c40.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>E) How <code>new</code> links prototypes?</h2>
<p>When we call the constructor function with <code>new</code>, we automate the following some actions:</p>
<ol>
<li><p>A new object is created</p>
</li>
<li><p>It binds <code>this</code> to the object</p>
</li>
<li><p>The constructor function’s prototype object becomes the <strong>proto</strong> property of the new object</p>
</li>
<li><p>It returns the object from the function</p>
</li>
</ol>
<pre><code class="language-typescript">function Player(username, score) {
  this.username = username;
  this.score = score;
}

Player.prototype.addScore = function () {
  this.score += 10;
};

Player.prototype.showMessage = function () {
  console.log("Welcome player!");
};

let player1 = new Player("Koushik", 20);

player1.addScore();

console.log(player1.score); // 30
</code></pre>
<hr />
<h2>F) Instances created from constructors</h2>
<p>When you create objects from using a <code>constructor function</code>, each object is called <code>Instance</code> of that constructor.</p>
<pre><code class="language-typescript">function User(name, points) {
  this.name = name;
  this.points = points;
}

User.prototype.increment = function () {
  this.points++;
};

const user1 = new User("Koushik", 5);
const user2 = new User("KK", 10);
</code></pre>
<p>These are created using <code>new User()</code> and follow the structure defined in <code>User</code>, behind the constructor function this <code>prototype</code> method works. They share methods from <code>User.prototype</code>.</p>
]]></content:encoded></item></channel></rss>