<?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-OOPS]]></title><description><![CDATA[Understanding-OOPS]]></description><link>https://mithila-dev-oops.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 10:44:37 GMT</lastBuildDate><atom:link href="https://mithila-dev-oops.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding Object-Oriented Programming in JavaScript]]></title><description><![CDATA[Have you ever noticed that in real projects, you end up creating many objects that look almost identical? One user object, another user object, another one — all with the same properties but different]]></description><link>https://mithila-dev-oops.hashnode.dev/understanding-object-oriented-programming-in-javascript</link><guid isPermaLink="true">https://mithila-dev-oops.hashnode.dev/understanding-object-oriented-programming-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[OOPS]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><dc:creator><![CDATA[Mithila Dk]]></dc:creator><pubDate>Sat, 14 Mar 2026 18:46:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/a27a3930-e5d7-47f2-af32-64b0b698cc34.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever noticed that in real projects, you end up creating many objects that look almost identical? One user object, another user object, another one — all with the same properties but different values. Typing the same structure again and again is not smart. That is exactly the problem <strong>Object-Oriented Programming (OOP)</strong> solves.</p>
<p>In this article, we will cover <strong>what OOP means, how classes work, how to create objects from a class, how constructors and methods work, and the basic idea of encapsulation</strong> — all with simple examples. By the end, you will be writing cleaner, reusable JavaScript code.</p>
<h2>What is Object-Oriented Programming?</h2>
<p>Object-Oriented Programming is a way of writing code by organising it around <strong>objects</strong> — instead of writing a long list of instructions.</p>
<p>The core idea is simple:</p>
<blockquote>
<p>You define a template once. Then you create as many objects from it as you need.</p>
</blockquote>
<p>Each object gets its own data but shares the same structure and behaviour.</p>
<h2>The Blueprint Analogy</h2>
<p>The best way to understand OOP is through a real-world analogy.</p>
<p>Think about a <strong>car blueprint</strong>. The blueprint is not a car itself — it is just the design. It says every car will have a brand, a color, and a speed. From that one blueprint, you can manufacture hundreds of different cars.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/0868e582-d5a8-46fd-b938-b76a562367ed.png" alt="" style="display:block;margin:0 auto" />

<p>In JavaScript:</p>
<ul>
<li><p>The <strong>blueprint</strong> is called a <strong>Class</strong></p>
</li>
<li><p>Each <strong>car</strong> made from it is called an <strong>Instance</strong> (or Object)</p>
</li>
</ul>
<h2>What is a Class in JavaScript?</h2>
<p>A class is a <strong>template</strong> for creating objects. You define it once using the <strong>class</strong> keyword, and then use it to create as many objects as you need.</p>
<pre><code class="language-javascript">class Car {
  // class body goes here
}
</code></pre>
<p>That is it - you have defined a class. Now let us make it useful.</p>
<h2>The Constructor Method</h2>
<p>The <strong>constructor</strong> is a special method inside a class. It runs <strong>automatically</strong> every time you create a new object from the class. This is where you set the initial properties.</p>
<pre><code class="language-javascript">class Car {
  constructor(brand, color, speed) {
    this.brand = brand;
    this.color = color;
    this.speed = speed;
  }
}
</code></pre>
<h2>What is 'this'?</h2>
<p><strong>this</strong> refers to the <strong>current object</strong> being created. When you write this.brand = brand, you are saying — store the brand value on this particular object.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/72fbaf2c-bab4-430f-aa5a-40bbdc78c46c.png" alt="" style="display:block;margin:0 auto" />

<h2>Creating Objects from a Class</h2>
<p>You use the <strong>new</strong> keyword to create an object (instance) from a class.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/9dbc68f0-92d0-4095-aeaa-7e7ad4958916.png" alt="" style="display:block;margin:0 auto" />

<p><strong>One class — three completely different objects.</strong> This is the power of OOP. You write the template once and reuse it as many times as needed.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/6e915c3c-8da5-4d1f-b51c-79b1f913805c.png" alt="" style="display:block;margin:0 auto" />

<h2>Methods Inside a Class</h2>
<p>A <strong>method</strong> is a function defined inside a class. It gives your objects behaviour — things they can do.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/28622121-7245-4dc3-8530-36c06ff0c341.png" alt="" style="display:block;margin:0 auto" />

<p>Every object created from <strong>car</strong> automatically has access to <strong>describe() and accelerate().</strong> You do not have to write those functions again for car2 or car3 — they just work.</p>
<blockquote>
<p><strong>Try it:</strong> Create <code>car2</code> and call <code>car2.describe()</code>. Notice how it uses car2's own data, not car1's — that is <code>this</code> doing its job!</p>
</blockquote>
<h2>Basic Idea of Encapsulation</h2>
<p><strong>Encapsulation</strong> means keeping related data and behaviour <strong>bundled together</strong> inside one class — and hiding internal details from the outside.</p>
<p>The car example already shows this. The <strong>speed</strong> property and the <strong>accelerate()</strong> method are both inside the <strong>Car</strong> class. The outside world just calls <strong>car1.accelerate(30) -&gt;</strong> it does not need to know how it works internally.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/c6306e19-e139-401c-ac5c-40759ada4b33.png" alt="" style="display:block;margin:0 auto" />

<p>Think of it like a TV remote — you press a button (method) without needing to know the electronics inside (internal logic). That is encapsulation in simple terms.</p>
<h2>Putting It All Together</h2>
<p>Let us now build a Student class from scratch — using everything we just learned.</p>
<img src="https://cdn.hashnode.com/uploads/covers/696f304bc3ffcbb856137e02/676e1cd3-f854-439f-8776-c10e059a99ed.png" alt="" style="display:block;margin:0 auto" />

<h2>Quick Reference Summary</h2>
<h3>What is OOP?</h3>
<p>A way of writing code organised around objects — using classes as templates.</p>
<h3>What is a Class?</h3>
<p>A blueprint/template defined using the <strong>class</strong> keyword. Used to create multiple objects with the same structure.</p>
<h3>What is a Constructor?</h3>
<p>A special method that runs automatically when you create a new object. Used to set initial property values.</p>
<h3>What is this ?</h3>
<p>Refers to the current object being created or used. <a href="http://this.name">this.name</a> means — the name property on this particular object.</p>
<h3>What is a Method?</h3>
<p>A function defined inside a class. Gives objects behaviour — things they can do.</p>
<h3>What is Encapsulation?</h3>
<p>Bundling related data and methods together inside a class. Keeps things organized and hides internal details.</p>
<h3>What is an Instance?</h3>
<p>An object created from a class using the <strong>new</strong> keyword.</p>
<h2>Conclusion</h2>
<p>OOP makes your code <strong>organized, reusable, and easier to maintain</strong>. Instead of writing the same object structure over and over, you define it once in a class and create as many instances as you need.</p>
<p>The key things to remember — a class is the blueprint, the constructor sets up the data, methods define the behaviour, and <strong>new</strong> creates the actual object.</p>
<p>Open VS Code, build the Student class from the assignment, create 5 different students, and call their methods. The best way to understand OOP is to build with it!</p>
]]></content:encoded></item></channel></rss>