<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Khafido Ilzam</title>
    <description>The latest articles on Forem by Khafido Ilzam (@khafido).</description>
    <link>https://forem.com/khafido</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1234658%2F8fc542c7-cdda-44ad-a8e6-0638a65595cd.png</url>
      <title>Forem: Khafido Ilzam</title>
      <link>https://forem.com/khafido</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/khafido"/>
    <language>en</language>
    <item>
      <title>Execution Context in JavaScript</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Thu, 05 Mar 2026 03:47:24 +0000</pubDate>
      <link>https://forem.com/khafido/execution-context-in-javascript-3hop</link>
      <guid>https://forem.com/khafido/execution-context-in-javascript-3hop</guid>
      <description>&lt;p&gt;Execution context is one of the most fundamental concepts in JavaScript — it's the environment in which JavaScript code is evaluated and executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is an Execution Context?
&lt;/h2&gt;

&lt;p&gt;Every time JavaScript runs code, it creates an execution context — a wrapper that holds information about the current code being run: what variables are available, what this refers to, and the outer environment it has access to.&lt;/p&gt;

&lt;p&gt;There are three types:&lt;br&gt;
&lt;strong&gt;Global Execution Context (GEC)&lt;/strong&gt; — created once when the script first runs&lt;br&gt;
&lt;strong&gt;Function Execution Context (FEC)&lt;/strong&gt; — created every time a function is invoked&lt;br&gt;
&lt;strong&gt;Eval Execution Context&lt;/strong&gt; — created inside eval() calls (rarely used, mostly avoided)&lt;/p&gt;

&lt;p&gt;Every execution context goes through two distinct phases:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1: Creation Phase (Memory / Hoisting Phase)&lt;/strong&gt;&lt;br&gt;
Before any code runs, the JavaScript engine scans the code and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates the &lt;strong&gt;Variable Environment&lt;/strong&gt; (stores var declarations, initialized to undefined)&lt;/li&gt;
&lt;li&gt;Creates the &lt;strong&gt;Lexical Environment&lt;/strong&gt; (stores let/const declarations in the Temporal Dead Zone)&lt;/li&gt;
&lt;li&gt;Stores &lt;strong&gt;function declarations&lt;/strong&gt; in memory in their entirety (fully hoisted)&lt;/li&gt;
&lt;li&gt;Determines the value of &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Creates a reference to the &lt;strong&gt;outer environment&lt;/strong&gt; (the scope chain)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why hoisting happens — variables and functions are placed into memory before code executes line by line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 2: Execution Phase&lt;/strong&gt;&lt;br&gt;
The engine runs the code line by line, assigns values, calls functions (which create new FECs), and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Call Stack
&lt;/h2&gt;

&lt;p&gt;To keep track of all the contexts, including global and functional, the JavaScript engine uses a call stack. A call stack is also known as an 'Execution Context Stack', 'Runtime Stack', or 'Machine Stack'.&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded, so it processes one execution context at a time using a call stack (a LIFO data structure). The GEC sits at the bottom; each function call pushes a new FEC on top; when a function returns, its context is popped off.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Implement OOP using TypeScript</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Mon, 08 Dec 2025 09:02:34 +0000</pubDate>
      <link>https://forem.com/khafido/implement-oop-using-typescript-2okm</link>
      <guid>https://forem.com/khafido/implement-oop-using-typescript-2okm</guid>
      <description>&lt;p&gt;Let’s learn how to implement all OOP principles in TypeScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classes &amp;amp; Objects&lt;/li&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Abstraction &amp;amp; Interface&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Class and Object
&lt;/h3&gt;

&lt;p&gt;A class is a blueprint, and objects are instances of the class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuj7qj0w0eph506hf6vxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuj7qj0w0eph506hf6vxu.png" alt="Class and Object" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyakn8nw3emds8goe02zk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyakn8nw3emds8goe02zk.png" alt="Object instance" width="800" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Encapsulation
&lt;/h3&gt;

&lt;p&gt;Encapsulation = hide internal data, expose only what is needed.&lt;br&gt;
Use &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;protected&lt;/code&gt;, and &lt;code&gt;public&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzrmjxl1afbwsr00uv3b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzrmjxl1afbwsr00uv3b.png" alt=" " width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Abstraction
&lt;/h3&gt;

&lt;p&gt;Abstraction = hide complexity and expose only what the user needs.&lt;br&gt;
Use abstract classes or interfaces. Interfaces define shape, and classes can implement them.&lt;/p&gt;

&lt;p&gt;You cannot create an object from it, but it can have abstract methods (no body) and normal methods. The child must implement (override) the abstract method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class can implement &lt;strong&gt;multiple&lt;/strong&gt; interfaces. But a class can extend &lt;strong&gt;only one&lt;/strong&gt; class&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Interfaces do &lt;strong&gt;NOT&lt;/strong&gt; contain implementation. Classes &lt;strong&gt;must&lt;/strong&gt; provide the implementation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F630g4785l2a88lx0e5a8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F630g4785l2a88lx0e5a8.png" alt=" " width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inheritance
&lt;/h3&gt;

&lt;p&gt;A class can inherit methods or data from another class. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu6fkq67bo0gx36cyd0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu6fkq67bo0gx36cyd0k.png" alt=" " width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5erh2ww4g3fc9oyj8w83.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5erh2ww4g3fc9oyj8w83.png" alt=" " width="800" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Polymorphism
&lt;/h3&gt;

&lt;p&gt;Polymorphism = same method name, different behavior.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdqbqyhu5yv0twokm82p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdqbqyhu5yv0twokm82p.png" alt=" " width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Full Example Code:&lt;br&gt;
 &lt;a href="https://snipsave.com/view-snippet?user=khafidoilzam&amp;amp;snippet_id=Fp13KgLloQpTnToegf" rel="noopener noreferrer"&gt;https://snipsave.com/view-snippet?user=khafidoilzam&amp;amp;snippet_id=Fp13KgLloQpTnToegf&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>REST vs RESTful API</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Tue, 18 Nov 2025 03:48:57 +0000</pubDate>
      <link>https://forem.com/khafido/rest-vs-restful-api-gm0</link>
      <guid>https://forem.com/khafido/rest-vs-restful-api-gm0</guid>
      <description>&lt;p&gt;The distinction between &lt;strong&gt;"REST API"&lt;/strong&gt; and &lt;strong&gt;"RESTful API"&lt;/strong&gt; lies in their adherence to the principles of &lt;code&gt;Representational State Transfer&lt;/code&gt; (REST) architectural style.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REST API:&lt;/strong&gt; This term generally refers to any API that utilizes HTTP and incorporates some, but not necessarily all, of the principles of REST. It may use clear URLs for resources and standard HTTP methods, such as GET and POST, but it may not strictly adhere to all the constraints defined by the REST architectural style.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RESTful API:&lt;/strong&gt; This term specifically denotes an API that fully conforms to all the constraints and principles of the REST architectural style.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key principles of REST:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Client-Server:&lt;/strong&gt; Separation of concerns between the client and server.&lt;br&gt;
&lt;strong&gt;Stateless:&lt;/strong&gt; Each request from the client to the server must contain all the information needed to understand the request, and the server must not store any client context between requests.&lt;br&gt;
&lt;strong&gt;Cacheable:&lt;/strong&gt; Responses must explicitly or implicitly indicate whether they are cacheable or non-cacheable to prevent clients from reusing stale or inappropriate data.&lt;br&gt;
&lt;strong&gt;Uniform Interface:&lt;/strong&gt; A standardized way for clients to interact with resources, including resource identification, resource manipulation through representations, self-descriptive messages, and &lt;code&gt;Hypermedia as the Engine of Application State&lt;/code&gt; (HATEOAS).&lt;br&gt;
&lt;strong&gt;Layered System:&lt;/strong&gt; An architecture composed of hierarchical layers, where each layer can communicate only with its immediate neighbors.&lt;br&gt;
&lt;strong&gt;Code on Demand (optional):&lt;/strong&gt; Servers can temporarily extend or customize client functionality by transferring executable code.&lt;/p&gt;

&lt;p&gt;In essence, while all RESTful APIs are a type of REST API, not all REST APIs are truly RESTful. A RESTful API is a specific implementation that rigorously adheres to the full set of REST constraints, ensuring greater consistency, scalability, and maintainability for large-scale web applications.&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JavaScript Memory Behavior</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Mon, 17 Nov 2025 08:56:16 +0000</pubDate>
      <link>https://forem.com/khafido/javascript-memory-behavior-10n6</link>
      <guid>https://forem.com/khafido/javascript-memory-behavior-10n6</guid>
      <description>&lt;p&gt;JavaScript uses two main memory spaces to store variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Call Stack&lt;/strong&gt; → where execution happens, stores variable references (pointers)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Heap&lt;/strong&gt; → where objects, arrays, and functions live&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is the Stack?
&lt;/h3&gt;

&lt;p&gt;Stack is a data structure that obeys the Last In First Out (LIFO) principle. This implies that the last item to enter the stack goes out first.&lt;/p&gt;

&lt;p&gt;Imagine a pile of books stacked up on a shelf. The last book ends up being the first to be removed. Data stored inside the stack can still be accessed easily.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Heap?
&lt;/h3&gt;

&lt;p&gt;Reference data are stored inside the heap. When reference data is created, the variable of the data is placed on the stack, but the actual value is placed on the heap.&lt;/p&gt;

&lt;p&gt;In JavaScript, different data types have different behaviors and locations in memory. So to reduce the chances of having bugs in your code, you need to understand the concept of mutability and immutability in JavaScript.&lt;/p&gt;

&lt;p&gt;But the real difference between &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; is how they are handled inside the Call Stack during creation and access, especially during hoisting.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; control whether you can reassign the variable. Mutability controls whether the value itself can be changed. These are two different things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mutability
&lt;/h3&gt;

&lt;p&gt;Mutability refers to data types that can be accessed and changed after they've been created and stored in memory. If a data type is mutable, that means that you can change it. Mutability allows you to modify existing values without creating new ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const staff = {
    name: "Strengthened",
    age: 43,
    hobbies: ["reading", "Swimming"]
}

const staff2 = staff;
staff2.age = 53;
console.log(staff.age); // 53
console.log(staff2.age); // 53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reference data does not copy values, but rather pointers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkmbi5m8przzjtjdc3rp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnkmbi5m8przzjtjdc3rp.png" alt="Mutable Data" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Changing the age of &lt;code&gt;staff2&lt;/code&gt; updates the age of the staff object. Now you know it is because both point to the same object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/khafido/how-to-clone-object-properties-369o"&gt;How to Clone Object Properly?&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Immutability
&lt;/h3&gt;

&lt;p&gt;Immutability refers to data types that you can't change after creating them, but that you can still access in memory. A value is immutable when altering it is impossible. Primitive data types are immutable, as we discussed above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let student1 = "Halina";
let student2 = student1;
student1 = "Brookes"

console.log(student1); // Brookes
console.log(student2); // Halina
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhi7r26dx8v2wlpdkhnk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhi7r26dx8v2wlpdkhnk.png" alt="Immutable Data" width="444" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://www.freecodecamp.org/news/mutability-vs-immutability-in-javascript/" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/mutability-vs-immutability-in-javascript/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Clone Object Properly?</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Mon, 17 Nov 2025 08:54:21 +0000</pubDate>
      <link>https://forem.com/khafido/how-to-clone-object-properties-369o</link>
      <guid>https://forem.com/khafido/how-to-clone-object-properties-369o</guid>
      <description>&lt;p&gt;You can clone the properties of an object using the &lt;code&gt;Object. assign()&lt;/code&gt; method and the spread operator. With these, you can change the properties of the cloned object without changing the properties of the object from which it was cloned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs80p10c6k0qegn250c11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs80p10c6k0qegn250c11.png" alt="Clone Object Properly" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How the &lt;code&gt;Object.assign()&lt;/code&gt; method Works
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;object.assign()&lt;/code&gt; method copies properties from an object (the source) into another object (the target) and returns the modified target object.&lt;/p&gt;

&lt;p&gt;Here's the syntax:&lt;br&gt;
&lt;code&gt;Object.assign(target, source)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const staff = {
    name: "Strengthened",
    age: 43,
    hobbies: ["reading", "Swimming"]
}

const staff2 = Object.assign({}, staff);
staff2.age = 53;

console.log(staff.age); // 43
console.log(staff2.age); // 53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How the Spread Operator Works
&lt;/h3&gt;

&lt;p&gt;Here's the syntax of the spread operator:&lt;br&gt;
&lt;code&gt;const newObj = {...obj}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using the spread operator is quite simple. You need to place three dots &lt;code&gt;...&lt;/code&gt; before the name of the object whose properties you intend to clone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const staff = {
    name: "Strengthened",
    age: 43,
    hobbies: ["reading", "Swimming"]
}

const staff2 = { ...staff };
staff2.age = 53;

console.log(staff.age); // 43
console.log(staff2.age); // 53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>JavaScript Data Types</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Mon, 17 Nov 2025 06:43:56 +0000</pubDate>
      <link>https://forem.com/khafido/javascript-data-types-46lk</link>
      <guid>https://forem.com/khafido/javascript-data-types-46lk</guid>
      <description>&lt;p&gt;Variables hold values, and every value has a specific data type that defines the kind of information it holds. These data types are broadly categorized into two groups: Primitive Data Types and Non-Primitive Data Types.&lt;/p&gt;

&lt;p&gt;Data types are categorized into &lt;code&gt;Primitive&lt;/code&gt; and &lt;code&gt;Non-Primitive (Reference)&lt;/code&gt; types in JavaScript. &lt;/p&gt;

&lt;h3&gt;
  
  
  Primitive
&lt;/h3&gt;

&lt;p&gt;When you assign a primitive value:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is stored &lt;strong&gt;directly in memory&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Copying the value creates a &lt;strong&gt;new independent value&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are &lt;code&gt;immutable&lt;/code&gt;, meaning you cannot change the value itself—only replace it.&lt;/p&gt;

&lt;p&gt;JavaScript has 7 primitive types:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Number
&lt;/h4&gt;

&lt;p&gt;All numbers (integer or floating point).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 10;
let y = 11.5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. String
&lt;/h4&gt;

&lt;p&gt;Text data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Hello World!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Boolean
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isOnline = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Null
&lt;/h4&gt;

&lt;p&gt;Intentional &lt;code&gt;empty&lt;/code&gt; value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data = null;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Undefined
&lt;/h4&gt;

&lt;p&gt;A variable declared but not assigned a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a; // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Symbol
&lt;/h4&gt;

&lt;p&gt;Symbol data type is used to create objects that will always be unique. These objects can be created using &lt;code&gt;Symbol&lt;/code&gt; constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sym = Symbol("Hello")
console.log(typeof(sym)); // Symbol
console.log(sym); // Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7. BigInt
&lt;/h4&gt;

&lt;p&gt;For very large integers beyond Number’s limit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let big = 12345678901234567890n;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Non-Primitive (Reference)
&lt;/h3&gt;

&lt;p&gt;This data type is mutable, which means you can change/modify it. Allows you to modify existing values without creating new ones. &lt;/p&gt;

&lt;p&gt;Non-primitive values are &lt;code&gt;stored by reference&lt;/code&gt;. When you assign an object to another variable, JavaScript &lt;code&gt;copies the reference, not the value&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;These are objects—more complex data structures. The main non-primitive types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Array&lt;/strong&gt; (actually a special type of object)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function&lt;/strong&gt; (also an object)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Map, Set, etc.&lt;/strong&gt; (still objects)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj1 = { age: 27 };
let obj2 = obj1;

obj2.age = 30;

console.log(obj1.age); // 30 (obj1 also changed)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why? Because both variables point to the same memory address.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript Declaration Variable</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Mon, 17 Nov 2025 05:35:02 +0000</pubDate>
      <link>https://forem.com/khafido/javascript-declaration-variable-3c8b</link>
      <guid>https://forem.com/khafido/javascript-declaration-variable-3c8b</guid>
      <description>&lt;p&gt;In JavaScript, variables are declared using one of three keywords: var, let, or const. These keywords differ in their scope, hoisting behavior, and re-assignment rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;var&lt;/code&gt; – the old way (avoid using it)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function-scoped&lt;/strong&gt; → only respects function boundaries.&lt;/li&gt;
&lt;li&gt;Can be &lt;strong&gt;re-declared&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Can be &lt;strong&gt;updated&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hoisted&lt;/strong&gt; → moved to the top of the scope, but initialized as undefined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can cause weird bugs because it ignores block scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var x = 1;
if (true) {
  var x = 2;  // same variable!
}
console.log(x); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;code&gt;let&lt;/code&gt; – recommended for variables that change
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block-scoped&lt;/strong&gt; → respects { } blocks.&lt;/li&gt;
&lt;li&gt;Can be &lt;strong&gt;updated&lt;/strong&gt;, but not re-declared in the &lt;strong&gt;same scope&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Also hoisted, but not usable before declared (“temporal dead zone”).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use let when the value needs to change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let count = 1;
count = 2; // OK
// let count = 3; // ❌ Error (same scope)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;code&gt;const&lt;/code&gt; – recommended default
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Block-scoped&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cannot&lt;/strong&gt; be updated or re-declared&lt;/li&gt;
&lt;li&gt;Best for values that should not change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects and arrays can still be modified, but the variable reference cannot change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PI = 3.14;
// PI = 4; // ❌ Error

const user = { name: "Khaf" };
user.name = "Fido"; // ✔ OK
// user = {} // ❌ Not allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;var&lt;/th&gt;
&lt;th&gt;let&lt;/th&gt;
&lt;th&gt;const&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Scope&lt;/td&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;td&gt;Block&lt;/td&gt;
&lt;td&gt;Block&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Re-declare&lt;/td&gt;
&lt;td&gt;✔ Yes&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update value&lt;/td&gt;
&lt;td&gt;✔ Yes&lt;/td&gt;
&lt;td&gt;✔ Yes&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hoisted&lt;/td&gt;
&lt;td&gt;Yes (weird)&lt;/td&gt;
&lt;td&gt;Yes (safer)&lt;/td&gt;
&lt;td&gt;Yes (safer)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;When to use&lt;/td&gt;
&lt;td&gt;Avoid&lt;/td&gt;
&lt;td&gt;Value changes&lt;/td&gt;
&lt;td&gt;Value doesn't change&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>How do Interfaces connect with OOP and SOLID?</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Wed, 12 Nov 2025 08:42:30 +0000</pubDate>
      <link>https://forem.com/khafido/how-do-interfaces-connect-with-oop-and-solid-2b3a</link>
      <guid>https://forem.com/khafido/how-do-interfaces-connect-with-oop-and-solid-2b3a</guid>
      <description>&lt;h4&gt;
  
  
  First, what’s an Interface again?
&lt;/h4&gt;

&lt;p&gt;An interface defines a contract — a list of methods or properties that a class must implement.&lt;br&gt;
It tells you what should exist, but not how it works.&lt;/p&gt;

&lt;p&gt;Now, let’s see how interfaces relate to the 4 pillars of OOP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Abstraction
&lt;/h3&gt;

&lt;p&gt;Interfaces are a tool to achieve abstraction.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction means showing only what’s necessary and hiding the details.&lt;/li&gt;
&lt;li&gt;An interface only describes behavior (what methods exist) — not how they’re done.
So, interface = pure abstraction layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Encapsulation
&lt;/h3&gt;

&lt;p&gt;Encapsulation is about hiding internal data and logic, while interfaces define public behavior.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The interface tells others what’s accessible publicly (the methods).&lt;/li&gt;
&lt;li&gt;The actual implementation inside the class (private variables, logic) remains encapsulated.
The interface exposes what can be done, not how it’s done.
Encapsulation keeps the hidden details safe inside.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Inheritance
&lt;/h3&gt;

&lt;p&gt;While inheritance lets a class inherit code and behavior,&lt;br&gt;
Interfaces let a class promise to follow a certain shape or behavior.&lt;br&gt;
You can also extend interfaces — similar to class inheritance.&lt;/p&gt;

&lt;p&gt;This allows structured hierarchies without code duplication — similar to inheritance but purely behavioral.&lt;/p&gt;

&lt;h3&gt;
  
  
  Polymorphism
&lt;/h3&gt;

&lt;p&gt;Interfaces are the foundation of polymorphism.&lt;/p&gt;

&lt;p&gt;Polymorphism allows you to treat different objects in the same way if they share a common interface.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Interfaces are the backbone of Abstraction and Polymorphism,&lt;br&gt;
while also supporting Encapsulation and flexible Inheritance.&lt;/p&gt;

&lt;p&gt;They define how objects should look — not how they work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Interfaces are at the core of two SOLID principles (ISP &amp;amp; DSP):
&lt;/h3&gt;

&lt;h4&gt;
  
  
  I — Interface Segregation
&lt;/h4&gt;

&lt;p&gt;Clients should not be forced to depend on interfaces they do not use.&lt;br&gt;
In simple terms, don’t make a big “God interface” that includes methods unrelated to certain classes.&lt;br&gt;
Instead, split it into smaller, more specific interfaces.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OOP Connection: Interfaces define abstraction.&lt;/li&gt;
&lt;li&gt;ISP ensures that abstraction stays clean and specific.&lt;/li&gt;
&lt;li&gt;Each interface represents a single responsibility for behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  D - Dependency Inversion Principle (DIP)
&lt;/h3&gt;

&lt;p&gt;High-level modules should not depend on low-level modules. Both should depend on abstractions (interfaces).&lt;/p&gt;

&lt;p&gt;Don’t make your main logic depend on specific classes — depend on interfaces instead.&lt;/p&gt;

&lt;p&gt;This allows you to swap implementations easily (for example, switching from MySQL to MongoDB) without breaking your main business logic.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OOP Connection: Interface provides abstraction between classes.&lt;/li&gt;
&lt;li&gt;DIP enforces that both high-level and low-level modules depend on that abstraction, not on each other directly.&lt;/li&gt;
&lt;li&gt;Promotes loose coupling, flexibility, and testability.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>beginners</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>What is an Interface?</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Wed, 12 Nov 2025 07:57:32 +0000</pubDate>
      <link>https://forem.com/khafido/what-is-an-interface-18m1</link>
      <guid>https://forem.com/khafido/what-is-an-interface-18m1</guid>
      <description>&lt;p&gt;In simple terms, an interface is like a contract or blueprint that says,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If you want to be part of this system, you must have these methods.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It doesn’t contain any actual code, only the rules — the names of functions or properties that a class must have.&lt;/p&gt;

&lt;p&gt;An interface is a contract that defines what methods or properties a class must have,&lt;br&gt;
but leaves the implementation details to the class itself.&lt;/p&gt;

&lt;p&gt;Example (TypeScript or Java-style syntax):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface PaymentProcessor {
  processPayment(amount: number): void;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, any class that implements this interface must define that method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreditCardPayment implements PaymentProcessor {
  processPayment(amount: number) {
    console.log(`Processing $${amount} via credit card`);
  }
}

class PayPalPayment implements PaymentProcessor {
  processPayment(amount: number) {
    console.log(`Processing $${amount} via PayPal`);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>SOLID and its relationship with OOP</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Wed, 12 Nov 2025 07:38:25 +0000</pubDate>
      <link>https://forem.com/khafido/solid-and-its-relationship-with-oop-jmm</link>
      <guid>https://forem.com/khafido/solid-and-its-relationship-with-oop-jmm</guid>
      <description>&lt;p&gt;&lt;strong&gt;SOLID&lt;/strong&gt; is like the “5 rules” to write good OOP code. Not just working code, but clean and maintainable code.&lt;/p&gt;

&lt;h4&gt;
  
  
  S — Single Responsibility Principle (SRP)
&lt;/h4&gt;

&lt;p&gt;A class should have only one reason to change. Each class, module, or function should handle only one responsibility. When a class has multiple reasons to change, it becomes fragile and tightly coupled.&lt;/p&gt;

&lt;h4&gt;
  
  
  O — Open/Closed Principle (OCP)
&lt;/h4&gt;

&lt;p&gt;Software entities should be open for extension, but closed for modification. You should be able to add new functionality without changing existing tested code.&lt;/p&gt;

&lt;h4&gt;
  
  
  L — Liskov Substitution Principle (LSP)
&lt;/h4&gt;

&lt;p&gt;Objects of a subclass should be replaceable with objects of the superclass without altering the correctness of the program. A child class should fully replace its parent without breaking anything.&lt;/p&gt;

&lt;h4&gt;
  
  
  I — Interface Segregation Principle (ISP)
&lt;/h4&gt;

&lt;p&gt;Don’t force classes to depend on things they don’t use. It’s better to have many small, specific interfaces than one large, general one.  &lt;/p&gt;

&lt;h4&gt;
  
  
  D — Dependency Inversion Principle (DIP)
&lt;/h4&gt;

&lt;p&gt;High-level modules (business logic) should not depend on low-level modules (e.g., database drivers).&lt;br&gt;
Both should depend on abstractions (interfaces or abstract classes).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SOLID Principle&lt;/th&gt;
&lt;th&gt;What it Means&lt;/th&gt;
&lt;th&gt;Relation to OOP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S — Single Responsibility&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One class = one job only.&lt;/td&gt;
&lt;td&gt;Keeps objects focused and simple (Encapsulation).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;O — Open/Closed&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Open for extension, closed for modification.&lt;/td&gt;
&lt;td&gt;Add new features without changing old code (Inheritance &amp;amp; Polymorphism).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;L — Liskov Substitution&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A child class should fully replace its parent without breaking anything.&lt;/td&gt;
&lt;td&gt;Keeps Inheritance safe and logical.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;I — Interface Segregation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Specific interfaces rather than one large, general one.&lt;/td&gt;
&lt;td&gt;Encourages cleaner Abstraction.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;D — Dependency Inversion&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Depend on abstractions, not concrete implementations.&lt;/td&gt;
&lt;td&gt;Promotes flexible and testable design (Abstraction &amp;amp; Encapsulation).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;SOLID&lt;/strong&gt; is how you design those objects so the system stays clean, scalable, and easy to change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SRP&lt;/strong&gt; keeps classes focused and easy to reason about. &lt;strong&gt;OCP&lt;/strong&gt; lets your system grow without breaking what works. &lt;strong&gt;LSP&lt;/strong&gt; ensures inheritance is trustworthy and substitutable. &lt;strong&gt;ISP&lt;/strong&gt; keeps interfaces lean so implementors aren't burdened. &lt;strong&gt;DIP&lt;/strong&gt; decouples layers so you can swap implementations freely — making your code testable, flexible, and future-proof.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>codequality</category>
      <category>programming</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>OOP (Object-Oriented Programming)</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Wed, 12 Nov 2025 07:04:35 +0000</pubDate>
      <link>https://forem.com/khafido/oop-object-oriented-programming-172</link>
      <guid>https://forem.com/khafido/oop-object-oriented-programming-172</guid>
      <description>&lt;h3&gt;
  
  
  What is OOP?
&lt;/h3&gt;

&lt;p&gt;Think of OOP like organizing things in your life. OOP is how you organize your code (using objects).&lt;/p&gt;

&lt;p&gt;An object is a self-contained unit with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State&lt;/strong&gt; — data it holds (properties/fields)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behavior&lt;/strong&gt; — things it can do (methods)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identity&lt;/strong&gt; — it's a distinct instance, separate from other objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Car&lt;/strong&gt; object&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Has:&lt;/strong&gt; color, brand, speed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can do&lt;/strong&gt;: start(), stop(), accelerate()&lt;/li&gt;
&lt;li&gt;And a Vehicle Ownership Document as car &lt;strong&gt;identity&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, instead of having a messy program with all logic mixed, OOP groups related data and behavior inside objects — making it organized, reusable, and easy to understand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Classes &amp;amp; Objects — The Foundation
&lt;/h3&gt;

&lt;p&gt;Before diving into the pillars, you need to understand classes and objects deeply.&lt;br&gt;
A class is a blueprint. An object is a live instance created from that blueprint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
  // Properties (state)
  make: string;
  model: string;
  year: number;
  private mileage: number = 0;

  // Constructor — called when creating an instance
  constructor(make: string, model: string, year: number) {
    this.make = make;
    this.model = model;
    this.year = year;
  }

  // Methods (behavior)
  drive(miles: number): void {
    if (miles &amp;gt; 0) this.mileage += miles;
    console.log(`Drove ${miles} miles in the ${this.make} ${this.model}.`);
  }
}

// Creating instances (objects) from the class
const car1 = new Car("Toyota", "Camry", 2022);
const car2 = new Car("Honda", "Civic", 2023);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;car1&lt;/code&gt; and &lt;code&gt;car2&lt;/code&gt; are completely independent objects — each has its own state.&lt;/p&gt;

&lt;h3&gt;
  
  
  4 Pillars of OOP (the mindset behind it)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt;&lt;br&gt;
Encapsulation is the process of bundling data (properties) and methods (functions) that operate on that data into a single unit of access (a class). Protect internal data and ensure that objects control how their own data is modified.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: When you drive a car, you don’t need to know how the engine works — just press &lt;code&gt;start&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;&lt;br&gt;
Abstraction means showing only relevant details of an object while hiding its internal implementation. Focus on what an object does, not how it does it. &lt;code&gt;interface&lt;/code&gt; and &lt;code&gt;abstract&lt;/code&gt; are tools to achieve abstraction.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: Your car’s “transmission” hides all the complicated process engine.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt;&lt;br&gt;
Inheritance allows one class (child/subclass) to inherit properties and methods from another class (parent/superclass), enabling the child class to reuse the code.  Use it for genuine "is-a" relationships.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: “SportsCar” can inherit from “Car” but adds more speed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt;&lt;br&gt;
Polymorphism (“many forms”) allows different classes to respond to the same method name in their own unique way. You can call the same method name, but each object does it differently.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: playSound() could mean barking for a Dog, or meowing for a Cat.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>REST vs RESTful API</title>
      <dc:creator>Khafido Ilzam</dc:creator>
      <pubDate>Wed, 05 Nov 2025 08:25:46 +0000</pubDate>
      <link>https://forem.com/khafido/rest-vs-restful-api-4e90</link>
      <guid>https://forem.com/khafido/rest-vs-restful-api-4e90</guid>
      <description>&lt;p&gt;A REST API is an architectural style for an application programming interface that uses Hypertext Transfer Protocol (HTTP) requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to reading, updating, creating and deleting operations related to resources.&lt;/p&gt;

&lt;p&gt;An API is code that enables two software programs to communicate with one another. The API's design spells out the proper way for a developer to write a program, or client, that uses the API to request services from another application, or the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Principles of the REST API. What makes a service RESTful?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;The interface must be uniform&lt;/code&gt;. This is the most important. All REST APIs must be consistent, providing resource identification in their URIs. They must use standard HTTP methods -- the CRUD operations (GET/POST/PUT, PATCH/DELETE) -- and represent resources in multiple formats, such as XML and JSON.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Client-server separation&lt;/code&gt;. The front end of communication -- the client -- and the back end -- the server -- must be independent of one another; the server must provide the resources, while the client hosts the UI.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Multiple layers&lt;/code&gt;. Though not required, the architecture allows for multiple layers, including proxies, load balancers and authentication; the client doesn't care if it's actually communicating with the web server.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;It must be stateless&lt;/code&gt;. Each API call is independent, meaning the server does not track the client's state between requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Caching&lt;/code&gt;. Responses use HTTP headers to determine whether they are cacheable; this reduces latency and improves performance.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Code return&lt;/code&gt;. Though not required, the architecture enables the server to return executable code to the client, such as JavaScript, if it is useful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a service to be considered a true RESTful web API, it must be designed and implemented all the principles.&lt;/p&gt;

&lt;p&gt;Credit: &lt;a href="https://www.techtarget.com/searchapparchitecture/definition/RESTful-API" rel="noopener noreferrer"&gt;https://www.techtarget.com/searchapparchitecture/definition/RESTful-API&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devjournal</category>
      <category>backend</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
