<?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[eedris blogs]]></title><description><![CDATA[On a journey through tech and sharing all I learn along the way.]]></description><link>https://blog.eedris.xyz</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 15:48:21 GMT</lastBuildDate><atom:link href="https://blog.eedris.xyz/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding The  "this" Parameter In JavaScript Once And For All]]></title><description><![CDATA[The this parameter in JavaScript is like that oddly concealed obstacle on a path that keeps tripping people. For the JavaScript beginner, it is often a thing of much unclarity, while for many a fairly-seasoned developer, it is one of those things the...]]></description><link>https://blog.eedris.xyz/understanding-the-this-parameter-in-javascript-once-and-for-all</link><guid isPermaLink="true">https://blog.eedris.xyz/understanding-the-this-parameter-in-javascript-once-and-for-all</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Idris Abdul-Lateef]]></dc:creator><pubDate>Wed, 20 Jul 2022 20:39:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1658344221363/0j9PRMKmT.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The <code>this</code> parameter in JavaScript is like that oddly concealed obstacle on a path that keeps tripping people. For the JavaScript beginner, it is often a thing of much unclarity, while for many a fairly-seasoned developer, it is one of those things they've figured out how to use but have never <em>truly</em> understood.</p>
<p>The <code>this</code> parameter is a vital ingredient in object-oriented JavaScript and a deep understanding of how it behaves is key to unlocking so many other concepts. By the end of this article, you should have gotten the insight needed to forever dispel any uncertainty you may have on <code>this</code> subject matter (<em>pun so intended</em>).</p>
<p><br /></p>
<h1 id="heading-what-exactly-is-this">What exactly is "this"?</h1>
<p>When a function is invoked, in addition to the explicit arguments passed to it, it receives other implicit parameters under the hood that are accessible within the body of the function. One of these is the <code>this</code> parameter which represents the object that is associated with the function invocation. It is often referred to as the <strong>function context</strong>.</p>
<p>However, <code>this</code> and the way it is determined is one of those things in JavaScript that are not so straightforward. The value of <code>this</code> is not only dictated by how and where a function is defined, but also, largely by how it is invoked. To begin making heads or tails of how <code>this</code> in a function is determined, we have to revisit our knowledge of function behavior.</p>
<p><br /></p>
<h1 id="heading-invoking-functions">Invoking functions</h1>
<p>There are four ways functions can be invoked in JavaScript, each with its own peculiarity:</p>
<ol>
<li>As  a  function—<code>averageJoe()</code>,  in which the  function  is  invoked  in  a  straightforward manner</li>
<li>As  a  method—<code>averageJoe.talk()</code>,  which  ties  the  invocation  to  an  object,  enabling object-oriented programming</li>
<li>As a constructor—<code>new AverageJoe()</code>, in which a new object is brought into being</li>
<li>Via the function’s apply or call methods—<code>averageJoe.call(someObject)</code> or <code>averageJoe.apply(someObject)</code></li>
</ol>
<p><em>— Secrets of the JavaScript Ninja, Second Edition</em></p>
<h2 id="heading-as-a-function">As a function</h2>
<p>When a function is invoked in a straightforward manner, its function context (that is, the <code>this</code> value) can be two things. In non-strict mode, the global context (the <code>window</code> object) becomes the function context. In strict mode, it will be <code>undefined</code>.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">averageJoe</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">strictJoe</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">    "use strict"</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
}

averageJoe()  <span class="hljs-comment">//  window object</span>
strictJoe()  <span class="hljs-comment">//  undefined</span>
</code></pre><p>The outcome is the same even if the function is defined within a function, so long it is invoked in a straightforward manner:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">outer</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">inner</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">strictInner</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-meta">    "use strict"</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
  }

  inner()  <span class="hljs-comment">//  window object</span>
  strictInner()  <span class="hljs-comment">//  undefined</span>
}
outer()
</code></pre><h2 id="heading-as-a-method">As a method</h2>
<p>Functions can also be properties in objects and in that capacity, they are known as methods. When a function is invoked through an object (as a method), the object itself becomes the function context and is accessible within the body of the method via the <code>this</code> parameter.</p>
<pre><code>averageJoe <span class="hljs-operator">=</span> {
  name: <span class="hljs-string">"Joe"</span>,
  talk: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    console.log(<span class="hljs-built_in">this</span>)
  }
}

averageJoe.talk()  <span class="hljs-comment">//  {name: "Joe", talk: ƒ}</span>
</code></pre><h2 id="heading-as-a-constructor">As a constructor</h2>
<p><a target="_blank" href="https://javascript.info/constructor-new">Constructor functions</a> are essentially the same old, run-of-the-mill functions we've been dealing with. As the name implies, we use them to "construct" new objects. To invoke a function as a constructor, we precede the function invocation with the <code>new</code> keyword.</p>
<p>When a function is invoked with the <code>new</code> keyword, a new object instance is created and provided to the function as its context. Within the function, any reference to <code>this</code> is a reference to the newly created object instance.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">AverageJoe</span>(<span class="hljs-params"></span>) </span>{
  console.log(<span class="hljs-built_in">this</span>)  <span class="hljs-comment">//  {} 'new object'</span>
  <span class="hljs-built_in">this</span>.<span class="hljs-built_in">name</span> <span class="hljs-operator">=</span> <span class="hljs-string">"Joe"</span>
  console.log(<span class="hljs-built_in">this</span>)  <span class="hljs-comment">//  {name: "Joe"}</span>
}
<span class="hljs-keyword">new</span> AverageJoe()
</code></pre><h2 id="heading-via-the-apply-or-call-method">Via the apply or call method</h2>
<p>Functions in JavaScript have access to two inbuilt methods: <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply">apply</a> and <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call">call</a>.</p>
<pre><code>func.apply(thisArg, argArray)

func.<span class="hljs-built_in">call</span>(thisArg, arg1, arg2, ...)
</code></pre><p>They allow us invoke a function and explicitly tie it to an object. Any object supplied to the <code>thisArg</code> parameter becomes the function context and what is referenced by <code>this</code> within the function.</p>
<pre><code>let averageJoe <span class="hljs-operator">=</span> {
  name: <span class="hljs-string">"Joe"</span>
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomGuy</span>(<span class="hljs-params"></span>) </span>{
  console.log(<span class="hljs-built_in">this</span>)
}

randomGuy.<span class="hljs-built_in">call</span>(averageJoe)  <span class="hljs-comment">//  {name: "Joe"}</span>
</code></pre><p><br /></p>
<h1 id="heading-taking-a-closer-look-at-functions">Taking a closer look at functions</h1>
<p>Functions being first-class objects in JavaScript mean they can, among other things, be assigned to things and passed around just like other value types. Of course, being objects, when we do assign or pass them around, what we are actually passing is their reference.</p>
<p>This flexibility around functions creates plentiful variety in the manner in which they are applied and used. Let's see how the concepts we've covered so far come into play in some of these scenarios.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loneGuy</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
}
loneGuy()  <span class="hljs-comment">//  window object</span>


<span class="hljs-keyword">let</span> averageJoe = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Joe"</span>,
  <span class="hljs-attr">talk</span>: loneGuy
}
averageJoe.talk()  <span class="hljs-comment">//   {name: "Joe", talk: ƒ}</span>


<span class="hljs-keyword">let</span> anotherAverageJoe = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Another Joe"</span>,
  <span class="hljs-attr">speak</span>: averageJoe.talk
}
anotherAverageJoe.speak()  <span class="hljs-comment">//  {name: "Another Joe", speak: ƒ}</span>


<span class="hljs-keyword">let</span> anotherLoneGuy = anotherAverageJoe.speak
anotherLoneGuy()  <span class="hljs-comment">//  window object</span>


anotherLoneGuy.apply(averageJoe)  <span class="hljs-comment">//  {name: "Joe", talk: ƒ}</span>
averageJoe.talk.call(anotherAverageJoe)  <span class="hljs-comment">//  {name: "Another Joe", speak: ƒ}</span>
</code></pre>
<p><br /></p>
<p>We begin by defining a function <code>loneGuy</code> that logs the current value of <code>this</code> within its function body:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">loneGuy</span>(<span class="hljs-params"></span>) </span>{
  console.log(<span class="hljs-built_in">this</span>)
}
</code></pre><p>When invoked as an ordinary, standalone function, the <code>window</code> object is outputted as the value of <code>this</code>:</p>
<pre><code>loneGuy()  //  <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>
</code></pre><p>We go on to create an object that has a <code>talk</code>  method that references the <code>loneGuy</code> function. When the <code>talk</code> method is invoked, its parent object, <code>averageJoe</code> now becomes the <code>this</code> value:</p>
<pre><code>let averageJoe <span class="hljs-operator">=</span> {
  name: <span class="hljs-string">"Joe"</span>,
  talk: loneGuy
}
averageJoe.talk()  <span class="hljs-comment">//   {name: "Joe", talk: ƒ}</span>
</code></pre><p>We create another object <code>anotherAverageJoe</code> whose <code>speak</code> method is a reference to <code>averageJoe.talk</code>. The <code>speak</code> method is invoked via its parent object <code>anotherAverageJoe</code>, which is rightly outputted as the <code>this</code> value.</p>
<pre><code>let anotherAverageJoe <span class="hljs-operator">=</span> {
  name: <span class="hljs-string">"Another Joe"</span>,
  speak: averageJoe.talk
}
anotherAverageJoe.speak()  <span class="hljs-comment">//  {name: "Another Joe", speak: ƒ}</span>
</code></pre><p>We create a new variable <code>anotherLoneGuy</code> and pass it a reference to <code>anotherAverageJoe.speak</code>. We go ahead to invoke it in a straightforward manner and sure enough, it gets the <code>window</code> object as its <code>this</code> value.</p>
<pre><code>let anotherLoneGuy <span class="hljs-operator">=</span> anotherAverageJoe.speak
anotherLoneGuy()  <span class="hljs-comment">//  window object</span>
</code></pre><p>Next, we invoke the newly created <code>anotherLoneGuy</code> via the built-in <code>apply</code> method and explicitly provide <code>averageJoe</code> as its function context. Expectedly, it runs and logs <code>averageJoe</code> as its <code>this</code> value. We also invoke <code>averageJoe.talk</code> via the <code>call</code> method and provide <code>anotherAverageJoe</code> as its function context which it duly outputs as its <code>this</code> value, despite being a method in <code>averageJoe</code>.</p>
<pre><code>anotherLoneGuy.apply(averageJoe)  <span class="hljs-comment">//  {name: "Joe", talk: ƒ}</span>
averageJoe.talk.<span class="hljs-built_in">call</span>(anotherAverageJoe)  <span class="hljs-comment">//  {name: "Another Joe", speak: ƒ}</span>
</code></pre><p>From all the passing around and reassigning of our initial function, we can see that whilst where and how a function is defined may have a hand in how its <code>this</code> value is arrived at, how it eventually gets invoked is the most determining factor.</p>
<p><br /></p>
<h1 id="heading-the-curious-case-of-arrow-functions">The curious case of arrow functions</h1>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a> came with ES6 and brought new elegance to how functions were wielded in JavaScript. They discarded some of the syntactic baggage of traditional functions and allowed functions to be expressed more succinctly and lucidly.</p>
<p>Arrow function expressions weren't just a syntactic retailoring of traditional functions though. They differed not only in syntax but slightly in behavior as well, one of which being how function context is determined. Arrow functions don’t have their own <code>this</code> value. Instead, they remember the value of the <code>this</code> parameter at the time of their definition.</p>
<p>Let's understand this by walking through some code.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomGuy</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">regularFunc</span>(<span class="hljs-params"></span>) </span>{
    console.log(<span class="hljs-built_in">this</span>)
  }

  const arrowFunc <span class="hljs-operator">=</span> () <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
    console.log(<span class="hljs-built_in">this</span>)
  }

  regularFunc()
  arrowFunc()
}
randomGuy()
<span class="hljs-comment">//  regularFunc –&gt; window object</span>
<span class="hljs-comment">//  arrowFunc –&gt; window object</span>


let averageJoe <span class="hljs-operator">=</span> {
  name: <span class="hljs-string">"Joe"</span>,
  talk: randomGuy
}
averageJoe.talk()
<span class="hljs-comment">//  regularFunc –&gt; window object</span>
<span class="hljs-comment">//  arrowFunc –&gt; {name: "Joe", talk: ƒ}</span>
</code></pre><p><br /></p>
<p>To begin, we define a <code>randomGuy</code> function, inside of which we house two other functions—a normal function <code>regularFunc</code> and an arrow function expression <code>arrowFunc</code>—both of which log the value of <code>this</code> inside their respective bodies. </p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">randomGuy</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">regularFunc</span>(<span class="hljs-params"></span>) </span>{
    console.log(<span class="hljs-built_in">this</span>)
  }

  const arrowFunc <span class="hljs-operator">=</span> () <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
    console.log(<span class="hljs-built_in">this</span>)
  }

  regularFunc()
  arrowFunc()
}
</code></pre><p>We invoke <code>randomGuy</code> the straightforward way and its function context becomes the <code>window</code> object. The code executes beyond the function definitions and reaches the <code>regularFunc</code> invocation. It is also invoked in a straightforward fashion, thus, it gets the <code>window</code> object as its function context as well. Next, <code>arrowFunc</code> is invoked and as an arrow function that doesn't determine its own <code>this</code> value, it takes on the <code>this</code> value existing at the time it was defined, which was the <code>window</code> object.</p>
<pre><code>randomGuy()
//  regularFunc –&gt; <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>
//  arrowFunc –&gt; <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>
</code></pre><blockquote>
<p>It is vital to understand the nuance here. Even though both functions ended up with the <code>window</code> object as their respective <code>this</code> values, the reasons were different. For <code>regularFunc</code> it was because it was invoked in straightforward manner, while for <code>arrowFunc</code> it was because the <code>window</code> object was the existing <code>this</code> value at the time of its definition and that was what it stuck with.</p>
</blockquote>
<p><br />
We go on to define an object <code>averageJoe</code> which has a <code>talk</code> method that is a reference to <code>randomGuy</code>.</p>
<pre><code>let averageJoe = {
  <span class="hljs-type">name</span>: "Joe",
  talk: randomGuy
}
</code></pre><p>When the <code>talk</code> method is invoked, the <code>this</code> value within its body becomes its parent object <code>averageJoe</code> through which it was invoked. We go past the function definitions and once again, <code>regularFunc</code> gets invoked in straightforward fashion making the <code>window</code> object its <code>this</code> value. Next, <code>arrowFunc</code> is invoked, and being an arrow function, it remembers the <code>this</code> value that existed at the time it was defined (the <code>averageJoe</code> object) and inherits it as its own <code>this</code> value.</p>
<pre><code>averageJoe.talk()
//  regularFunc –&gt; <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>
//  arrowFunc –&gt; {<span class="hljs-type">name</span>: "Joe", talk: ƒ}
</code></pre><p>Arrow functions get their function context from the existing function context at the time of their definition. They remember this context and stick faithfully to it no matter how they're invoked later on.</p>
<h2 id="heading-arrow-functions-as-callbacks">Arrow functions as callbacks</h2>
<p>An area where the practicality of arrow functions comes to bear is in the use of callback functions. Traditional functions have always been quirky in this regard and prior to arrow functions, developers had to resort to workarounds when using them as callbacks in certain cases. Take a look at this code for example:</p>
<pre><code>let averageJoe <span class="hljs-operator">=</span> {
  hobbies: [<span class="hljs-string">"reading"</span>, <span class="hljs-string">"coding"</span>, <span class="hljs-string">"blogging"</span>],
  printHobby: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">hobby</span>) </span>{
    console.log(hobby)
  },
  printHobbies: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">this</span>.hobbies.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">hobby</span>) </span>{
      <span class="hljs-built_in">this</span>.printHobby(hobby)
    })
  }
}
averageJoe.printHobbies()  <span class="hljs-comment">//  Uncaught TypeError: this.printHobby is not a function</span>
</code></pre><p>In this scenario, using a traditional function expression as our callback brought us nothing but heartbreak. When the anonymous callback function we passed to the <code>forEach</code> method gets invoked, it takes on the <code>window</code> object as its function context and which, of course, isn't where the <code>printHobby</code> method resides. Hence, the error we got.</p>
<p>However, when we make use of an arrow function instead, we see that it captures the prevailing <code>this</code> value at the time of its definition (the <code>averageJoe</code> object) and this, in turn, leads to the output we desire:</p>
<pre><code><span class="hljs-comment">// ...</span>

  printHobbies: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">this</span>.hobbies.forEach(hobby <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
      <span class="hljs-built_in">this</span>.printHobby(hobby)
    })
  }
}
averageJoe.printHobbies()  <span class="hljs-comment">//  "reading", "coding", "blogging"</span>
</code></pre><h2 id="heading-using-arrow-functions-as-methods">Using arrow functions as methods</h2>
<p>You should be a bit careful with arrow functions. Their characteristic of inheriting the <code>this</code> parameter leads to a quirk when we use them as methods.</p>
<p>Take this for example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> averageJoe = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Joe"</span>,
  <span class="hljs-attr">talk</span>: <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>)
   }
}

averageJoe.talk()  <span class="hljs-comment">//  window object</span>
</code></pre>
<p>Within the <code>talk</code> method, <code>this</code> now references the <code>window</code> object as opposed to its parent object <code>averageJoe</code>. Crazy, right? Don't panic, I will explain.</p>
<p>It's actually quite simple. Arrow functions always sticking to the <code>this</code> value existing at the time of their definition means that they won't take their parent objects as their function context when they're invoked through them as methods. In this particular case, <code>averageJoe</code> is created in global JavaScript code (that is, not within a function) where the value of <code>this</code> is the <code>window</code> object and that is what the arrow function expression used for the <code>talk</code> method stuck with.</p>
<p>This same behavior of arrow functions leads to a different outcome when we come to constructor functions:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">AverageJoe</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">this</span>.<span class="hljs-built_in">name</span> <span class="hljs-operator">=</span> <span class="hljs-string">"Joe"</span>
  <span class="hljs-built_in">this</span>.talk <span class="hljs-operator">=</span> () <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
      console.log(<span class="hljs-built_in">this</span>)
    }
}

let averageJoe <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> AverageJoe()
averageJoe.talk()  <span class="hljs-comment">//  {name: "Joe", talk: ƒ}</span>
</code></pre><p>As we know, invoking constructor functions with the <code>new</code> keyword leads to a new object instance being created and made the function context. So, in essence, the object that we are passing the arrow function to as a method is also the existing function context at the time it was defined and that is what it will stick to whenever it is invoked.</p>
<p>In fact, <em>however</em> it is invoked.</p>
<pre><code>averageJoe.talk()  //  {<span class="hljs-type">name</span>: "Joe", talk: ƒ}

let loneGuy = averageJoe.talk
loneGuy()  //  {<span class="hljs-type">name</span>: "Joe", talk: ƒ}  <span class="hljs-keyword">not</span> <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>

averageJoe.talk.<span class="hljs-keyword">call</span>(<span class="hljs-keyword">window</span>)  //  {<span class="hljs-type">name</span>: "Joe", talk: ƒ}  still <span class="hljs-keyword">not</span> <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>

let anotherLoneGuy = averageJoe.talk.bind(<span class="hljs-keyword">window</span>)
anotherLoneGuy()  //  {<span class="hljs-type">name</span>: "Joe", talk: ƒ}  lol, still <span class="hljs-keyword">not</span> <span class="hljs-keyword">window</span> <span class="hljs-keyword">object</span>
</code></pre><blockquote>
<p>On a quick note, you shouldn't use arrow functions as methods as they aren't fit for that purpose. This was only for demonstration purposes.</p>
</blockquote>
<p><br /></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>We've covered ample ground on this topic. We started off by getting to know what <code>this</code> was. We looked at functions, the variety of ways they are invoked, and how they affect how <code>this</code> is determined. We also took a good look at arrow functions and their interesting peculiarities.</p>
<p>Hopefully, this article has done enough to demystify and help you understand the <code>this</code> parameter once and for all. Thanks for reading!</p>
]]></content:encoded></item><item><title><![CDATA[A Comprehensive Guide To Creating and Publishing Your First NPM Package]]></title><description><![CDATA[If you've been writing JavaScript long enough, chances are that you'd have used an NPM package in a project at one point or the other. NPM packages are composed of single or multiple JavaScript files which provide simple or complex functionalities th...]]></description><link>https://blog.eedris.xyz/a-comprehensive-guide-to-creating-and-publishing-your-first-npm-package</link><guid isPermaLink="true">https://blog.eedris.xyz/a-comprehensive-guide-to-creating-and-publishing-your-first-npm-package</guid><category><![CDATA[npm]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Idris Abdul-Lateef]]></dc:creator><pubDate>Sat, 18 Jun 2022 05:37:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1655522994301/xF2aibvne.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you've been writing JavaScript long enough, chances are that you'd have used an NPM package in a project at one point or the other. NPM packages are composed of single or multiple JavaScript files which provide simple or complex functionalities that can be reused throughout a project. NPM itself is the default package manager for Node.js which handles the installation, upgrading, configuration, and management of the packages and dependencies of a project.</p>
<p>All of these packages live in a centralized repository known as the NPM Registry and are the handiwork of developers scattered around the globe. This article aims to show you the ropes on how to go about creating and publishing your own NPM package.
<br />
<br /></p>
<h1 id="heading-what-are-we-going-to-make">What are we going to make?</h1>
<p>Programmers that work with frontend libraries like React know that directly modifying the values in a component's state object is a no-go area. This often means that developers have to, first of all, make a copy of whatever value they need from the state into new a variable before it can be used for anything. For arrays and objects, this can be more tricky as JavaScript objects are copied by reference and so, arrays and objects have to be copied more carefully to avoid passing reference to the same state property inadvertently. And with components' state objects usually having properties consisting of nested objects and arrays, trying to decouple and safely copy them from the state quickly becomes a task.</p>
<p>Well, developers can now breathe a sigh of relief! What we're going to be creating is an NPM library that allows us to make perfect clones of objects and arrays effortlessly.
<br />
<br /></p>
<h1 id="heading-setting-up-an-npm-registry-account">Setting up an NPM Registry account</h1>
<p>To sign up for an account, click <a target="_blank" href="https://www.npmjs.com/">here</a></p>
<p>1) Click the <strong>"Sign Up"</strong> button</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655222276844/mezFmovb0.png" alt="chrome_j2mEakJyjC.png" />
<br /></p>
<p>2) Fill all the fields and click on <strong>"Create an Account"</strong> (you'd receive an email shortly after). Take note of the credentials you entered as you'd be needing it soon.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655222708352/PMsY1stiK.png" alt="chrome_p3hSL4vxkE.png" />
<br /></p>
<p>3) After receiving the email confirming your newly created account, login to the NPM Registry from your terminal:</p>
<pre><code>npm <span class="hljs-keyword">login</span>
</code></pre><p><em>You will be prompted for your <strong>username</strong>, <strong>password</strong> and <strong>email</strong></em>.
<br />
<br /></p>
<h1 id="heading-writing-the-code">Writing the code</h1>
<p>Create a new folder <strong>object-cloner</strong> in your IDE. Inside it, create a new file <strong>index.js</strong> and write out this <code>clone</code> function:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">clone</span>(<span class="hljs-params">item</span>) </span>{
<span class="hljs-comment">// Clones an array or object using</span>
<span class="hljs-comment">// the spread syntax</span>

  <span class="hljs-keyword">return</span> Array.isArray(item) ? [...item] : { ...item };
}
</code></pre><p>Now, to test that the code is working properly, we're going to add these lines of code to <strong>index.js</strong>:</p>
<pre><code>let arr <span class="hljs-operator">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
let arrClone <span class="hljs-operator">=</span> clone(arr);
arrClone.shift();
console.log(<span class="hljs-string">"- arr"</span>, arr);  <span class="hljs-comment">// - arr [1, 2, 3]  Original array is unaffected</span>
console.log(<span class="hljs-string">"- arrClone"</span>, arrClone);  <span class="hljs-comment">//  - arrClone [2, 3]</span>
</code></pre><p>Next, run the code from your terminal:</p>
<pre><code>node <span class="hljs-keyword">index</span>.js
</code></pre><p>This should be the output you get:
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655225353398/mlhPqzUIz.png" alt="image.png" />
<br /></p>
<p>Seeing as our function works fine, let's remove the last set of lines we added and go ahead to export the <code>clone</code> function with a <code>module.exports</code> statement. Your <strong>index.js</strong> file should now look like this:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">clone</span>(<span class="hljs-params">item</span>) </span>{
<span class="hljs-comment">// Clones an array or object using</span>
<span class="hljs-comment">// the spread syntax</span>

  <span class="hljs-keyword">return</span> Array.isArray(item) ? [...item] : { ...item };
}

module.exports <span class="hljs-operator">=</span> clone;
</code></pre><blockquote>
<p>Whatever you export from <strong>index.js</strong> is what will be available for importing when the library is installed in a project.</p>
</blockquote>
<p>Alright, let's go ahead and publish what we've built.
<br /></p>
<h2 id="heading-packagejson">Package.json</h2>
<p>Well, not just yet. Every NPM package requires a <strong>package.json</strong> file—you can't publish without it. Create a <strong>package.json</strong> file initialized with the defaults by running this in the package root directory:</p>
<pre><code>npm <span class="hljs-keyword">init</span> -y
</code></pre><p>The newly created <strong>package.json</strong> file should contain something like this:</p>
<pre><code>{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"object-cloner"</span>,
  <span class="hljs-attr">"version"</span>: <span class="hljs-string">"1.0.0"</span>,
  <span class="hljs-attr">"description"</span>: <span class="hljs-string">""</span>,
  <span class="hljs-attr">"main"</span>: <span class="hljs-string">"index.js"</span>,
  <span class="hljs-attr">"scripts"</span>: {
    <span class="hljs-attr">"test"</span>: <span class="hljs-string">"echo \"Error: no test specified\" &amp;&amp; exit 1"</span>
  },
  <span class="hljs-attr">"keywords"</span>: [],
  <span class="hljs-attr">"author"</span>: <span class="hljs-string">""</span>,
  <span class="hljs-attr">"license"</span>: <span class="hljs-string">"ISC"</span>
}
</code></pre><p>Okay, let's take a moment to take note of somethings. Firstly, there's the <strong>"name"</strong> field which represents the name of the package. It has to be lowercase and MUST be unique; it can't bear the same name as an existing NPM package. You can go to the homepage of the <a target="_blank" href="https://www.npmjs.com/">NPM Registry</a> and search to see if there's something by that name already.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655286122815/2IqQ7FKRJ.png" alt="chrome_op4pgtoF8y.png" /></p>
<p>If you do want a particular name for your package which happens to be taken already, you could make it a <strong>scoped package</strong> instead. Scoped packages come in the form <code>@username/package-name</code>, where a package name is prefixed with an NPM account followed by a slash. You should change the package name in your <strong>package.json</strong> file to something else ("object-cloner" is already taken by yours faithfully) or to this instead:</p>
<pre><code>{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"@your-username/object-cloner"</span>
}
</code></pre><p>There's the <strong>"version"</strong> field as well which, together with the <strong>"name"</strong> field, make up the two most crucial things in the <strong>package.json</strong> file. Changes to a published package should be accompanied with changes to the <strong>"version"</strong> field. NPM follows a versioning system called <a target="_blank" href="https://semver.org"><strong>SemVer</strong></a>, which is short for <strong>Semantic Versioning</strong>.</p>
<p>The summary of the gist is:</p>
<blockquote>
<p>Given a version number MAJOR.MINOR.PATCH, increment the:</p>
<ol>
<li>MAJOR version when you make incompatible API changes,</li>
<li>MINOR version when you add functionality in a backwards compatible manner, and</li>
<li><p>PATCH version when you make backwards compatible bug fixes.</p>
<p>(https://semver.org)</p>
</li>
</ol>
</blockquote>
<p>The <strong>"description"</strong> field is where we include a succinct description of our package. Also, there is the <strong>"main"</strong> field which denotes the entry point to our package, which is <strong>index.js</strong> in our case. The <strong>"keywords"</strong> field is an array of strings which will be the keywords that are associated with our package and helps people discover it. Lastly, there is the <strong>"author"</strong> field and this is where we put our name, email and website.</p>
<p>After filling the fields, you should have something like this:</p>
<pre><code>{
  <span class="hljs-attr">"name"</span>: <span class="hljs-string">"object-cloner"</span>,  <span class="hljs-comment">// "@your-username/object-cloner"</span>
  <span class="hljs-attr">"version"</span>: <span class="hljs-string">"1.0.0"</span>,
  <span class="hljs-attr">"description"</span>: <span class="hljs-string">"A simple utility library for cloning objects and arrays"</span>,
  <span class="hljs-attr">"main"</span>: <span class="hljs-string">"index.js"</span>,
  <span class="hljs-attr">"scripts"</span>: {
    <span class="hljs-attr">"test"</span>: <span class="hljs-string">"echo \"Error: no test specified\" &amp;&amp; exit 1"</span>
  },
  <span class="hljs-attr">"keywords"</span>: [<span class="hljs-string">"clone"</span>, <span class="hljs-string">"objects"</span>, <span class="hljs-string">"arrays"</span>],
  <span class="hljs-attr">"author"</span>: <span class="hljs-string">"eedris &lt;alabialade@gmail.com&gt; (https://twitter.com/eedrxs) "</span>,
  <span class="hljs-attr">"license"</span>: <span class="hljs-string">"ISC"</span>
}
</code></pre><p><br /></p>
<h1 id="heading-publishing">Publishing</h1>
<p>Alright, we can now publish. In your terminal, run:</p>
<pre><code><span class="hljs-built_in">npm</span> publish
</code></pre><p>If all goes well, you should see something like this:</p>
<pre><code>npm notice 
npm notice 📦  object<span class="hljs-operator">-</span>cloner@<span class="hljs-number">1.0</span><span class="hljs-number">.0</span>
npm notice <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> Tarball Contents <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> 
npm notice 176B index.js    
npm notice 365B package.json
npm notice <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> Tarball Details <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>
npm notice name:          object<span class="hljs-operator">-</span>cloner
npm notice version:       <span class="hljs-number">1.0</span><span class="hljs-number">.0</span>
npm notice filename:      object<span class="hljs-operator">-</span>cloner<span class="hljs-number">-1.0</span><span class="hljs-number">.0</span>.tgz
npm notice package size:  <span class="hljs-number">459</span> B
npm notice unpacked size: <span class="hljs-number">541</span> B
npm notice shasum:        e5fdba39cf9ec463a4ec777b9247fd55ce19d3c5
npm notice integrity:     sha512<span class="hljs-operator">-</span>Pv6n04FnBOd<span class="hljs-operator">+</span>k[...]V<span class="hljs-operator">/</span>APMfXSQhaEA<span class="hljs-operator">=</span><span class="hljs-operator">=</span>
npm notice total files:   <span class="hljs-number">2</span>
npm notice
<span class="hljs-operator">+</span> object<span class="hljs-operator">-</span>cloner@<span class="hljs-number">1.0</span><span class="hljs-number">.0</span>
</code></pre><p>Now, that wasn't so hard, was it? 😎</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655501846112/MlSSJFjKx.png" alt="chrome_P7GqoPrzjU.png" /></p>
<blockquote>
<p>NOTE: If you decided to publish your package as a scoped package, running <code>npm publish</code> will fail and give you an error like this:</p>
<pre><code>npm ERR<span class="hljs-operator">!</span> code E402
npm ERR<span class="hljs-operator">!</span> <span class="hljs-number">402</span> Payment Required <span class="hljs-operator">-</span> PUT https:<span class="hljs-comment">// registry.npmjs.org/@eedris%2fobject-cloner - You must sign up for private packages</span>
</code></pre><p>Why is this so? Well, this is because scoped packages are published privately by default as they are also used by companies (or individuals) to create packages that are used internally. To go around this, we simply have to let NPM know that we are magnanimous people and actually want our scoped package to be available publicly. To do that, we run:</p>
<pre><code>npm publish <span class="hljs-operator">-</span><span class="hljs-operator">-</span>access<span class="hljs-operator">=</span><span class="hljs-keyword">public</span>
</code></pre></blockquote>
<p><br /></p>
<h1 id="heading-installing-and-using-the-package">Installing and using the package</h1>
<p>Now that we've published our package, let's put it to work. Open up a new folder in your IDE and install the package from your terminal:</p>
<pre><code>npm <span class="hljs-keyword">install</span> <span class="hljs-keyword">object</span>-cloner
</code></pre><p>Next, create an <strong>index.js</strong> file and fill it with these lines of code:</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">clone</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"object-cloner"</span>;

let obj <span class="hljs-operator">=</span> { name: <span class="hljs-string">"eedris"</span>, id: <span class="hljs-number">123</span> };
let objClone <span class="hljs-operator">=</span> clone(obj);
<span class="hljs-keyword">delete</span> objClone.id;
console.log(<span class="hljs-string">"- obj"</span>, obj);
console.log(<span class="hljs-string">"- objClone"</span>, objClone);
</code></pre><blockquote>
<p>NOTE: You may need to include the <strong>"type"</strong> field in your <strong>package.json</strong> and set it to <strong>"module"</strong> to be able to use the <strong>import</strong> syntax in your code. Check to see if it is already set; if it isn't add it to your <strong>package.json</strong>:</p>
<pre><code><span class="hljs-string">"type"</span>: <span class="hljs-string">"module"</span>
</code></pre></blockquote>
<p>Running <code>node index.js</code> in your terminal should give you this output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655300952933/or3RVr1OL.png" alt="Code_UinD4St2rD.png" /></p>
<p>We really should give ourselves a pat on the back at this point. We've published, installed and also made use of our package in our code.
<br />
<br /></p>
<h1 id="heading-making-changes">Making changes</h1>
<p>If you have a sharp eye, chances are that you'd have noticed an issue with our <code>clone</code> function. Whilst it does create clones of objects or arrays, the cloning only goes one level deep.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">clone</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"object-cloner"</span>;

let obj <span class="hljs-operator">=</span> { tutor: { name: <span class="hljs-string">"eedris"</span>, id: <span class="hljs-number">123</span> } };
let objClone <span class="hljs-operator">=</span> clone(obj);
<span class="hljs-keyword">delete</span> objClone.tutor.id;
console.log(<span class="hljs-string">"- obj"</span>, obj); <span class="hljs-comment">// - obj { tutor: { name: 'eedris' } }  😨</span>
</code></pre><p>As you can see, removing the <code>tutor.id</code> property from <code>objClone</code> also removed it from <code>obj</code>. Since our <code>clone</code> function only goes one level deep, nested objects or arrays beyond the first level still get passed as references and not as fresh copies.</p>
<p>To rectify this, we're going to rewrite our clone function to not only clone, but to <em>deep-clone</em>.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">deepClone</span>(<span class="hljs-params">item</span>) </span>{  <span class="hljs-comment">// renamed to "deepClone"</span>
  <span class="hljs-comment">//  Deeply clones an object or array</span>

  <span class="hljs-keyword">return</span> JSON.parse(JSON.stringify(item));
}
</code></pre><p>Remember from earlier that each update to a package has to be accompanied with a change to its version. So, we have to determine the kind of change we made to the package and increment the package's version in a manner that reflects that change and goes in line with the <a target="_blank" href="https://semver.org/">SemVer</a> system. To do that, we make use of the command: </p>
<pre><code>npm version <span class="hljs-operator">&lt;</span>update_type<span class="hljs-operator">&gt;</span>
</code></pre><blockquote>
<p> where <strong>"update_type"</strong> can be either <strong>major</strong>, <strong>minor</strong> or <strong>patch</strong></p>
</blockquote>
<p>We reworked our cloning logic. More pertinently, we renamed the function name and this sort of change makes this new version of our package backward-incompatible. A project that was written using the earlier version of our package will spit out errors if we tried to make use of this new version with it as our package no longer exports the <code>clone</code> function that it relies on. This calls for a major update, so run:</p>
<pre><code>npm <span class="hljs-keyword">version</span> major
</code></pre><p>Running this takes the <strong>"version"</strong> field in our <strong>package.json</strong> file to 2.0.0. To publish the update, run:</p>
<pre><code><span class="hljs-built_in">npm</span> publish
</code></pre><p><em>Drum roll...</em> 🥁🥁</p>
<pre><code>npm notice 
npm notice 📦  object<span class="hljs-operator">-</span>cloner@<span class="hljs-number">2.0</span><span class="hljs-number">.0</span>
npm notice <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> Tarball Contents <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> 
npm notice 256B index.js    
npm notice 365B package.json
npm notice <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span> Tarball Details <span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>
npm notice name:          object<span class="hljs-operator">-</span>cloner
npm notice version:       <span class="hljs-number">2.0</span><span class="hljs-number">.0</span>
npm notice filename:      object<span class="hljs-operator">-</span>cloner<span class="hljs-number">-2.0</span><span class="hljs-number">.0</span>.tgz
npm notice package size:  <span class="hljs-number">504</span> B
npm notice unpacked size: <span class="hljs-number">621</span> B
npm notice shasum:        1bb417d5d2cc87aeb1789dbca8b08e1d79af5d37
npm notice integrity:     sha512<span class="hljs-operator">-</span><span class="hljs-operator">/</span>XtyouHWgotLv[...]acqQN1WAZC<span class="hljs-operator">+</span>9A<span class="hljs-operator">=</span><span class="hljs-operator">=</span>
npm notice total files:   <span class="hljs-number">2</span>
npm notice
<span class="hljs-operator">+</span> object<span class="hljs-operator">-</span>cloner@<span class="hljs-number">2.0</span><span class="hljs-number">.0</span>
</code></pre><p>Our package is successfully updated! 🥳🎉
<br />
<br /></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>We've been able to create and publish an NPM package, as well as make updates to it. We were also able to install it and put it to use.</p>
<p>It is recommended you include a <strong>README.md</strong> markdown file in your package root directory to describe what it's about and also give examples of how to use it. I added a <strong>README.md</strong> to my package and this is how it now looks on the NPM Registry:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655523338985/JxCf-4sLc.png" alt="image.png" /></p>
<p>Our package is tiny and definitely not the most sophisticated. However, the primary focus here was about illustrating the process, and not so much about the product itself. NPM packages can be much more grand and more often than not, involve the use of other NPM packages as well. It all depends on the problems you're trying to solve or the functionalities you want to provide.</p>
<p>With all we've done, you should now know all you need to know to start creating your own NPM packages. Thanks for reading!</p>
]]></content:encoded></item><item><title><![CDATA[How to Create Custom Subdomains on Vercel, Heroku and Netlify]]></title><description><![CDATA[Introduction
After you finish building a project, you'd usually want to take it out of your localhost and put it somewhere else where you or others can access it as well. The next point of call would be to deploy the project to any of the several clo...]]></description><link>https://blog.eedris.xyz/how-to-create-custom-subdomains-on-vercel-heroku-and-netlify</link><guid isPermaLink="true">https://blog.eedris.xyz/how-to-create-custom-subdomains-on-vercel-heroku-and-netlify</guid><category><![CDATA[Netlify]]></category><category><![CDATA[Heroku]]></category><category><![CDATA[Vercel]]></category><category><![CDATA[hosting]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Idris Abdul-Lateef]]></dc:creator><pubDate>Tue, 14 Jun 2022 00:17:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1655164507636/L8Rcqaqhv.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>After you finish building a project, you'd usually want to take it out of your localhost and put it somewhere else where you or others can access it as well. The next point of call would be to deploy the project to any of the several cloud hosting platforms available.</p>
<p>Some of these hosting platforms even give you free hosting and if you are like virtually every other developer, chances are that's what you'd be opting for. Of course, what you get is a subdomain and limited resources—but that is often more than enough for most stuff you'd be building. You're usually able to set the subdomain name from which your project will be accessed at the point of deployment. But, as it happens sometimes, your preferred subdomain may already be taken (or maybe you're just in a hurry) and you may opt for an auto-generated subdomain name which you can change later on if you wish.</p>
<p>However, after coming across several sizable projects (and even a personal portfolio site!) with auto-generated subdomains of the <strong>"notorious-badlands-47642.hostingplatform.app"</strong> kind, it became clear to me many either don't know they can customize their projects' subdomain names or just don't know how to. And that was why I set out to write this article. Picking three among the top cloud hosting platforms used by developers, I'd be showing you how to do just that.
<br /></p>
<h2 id="heading-vercel">Vercel</h2>
<p>1) Log in and click on the project whose subdomain name you want to change</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655139728886/Jeh0cRLBY.png" alt="chrome_gR7nry6pf6.png" />
<br /></p>
<p>2) After it opens up, go to the settings page and click on
<strong>"Domains"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655139910906/SGKNFNu3n.png" alt="chrome_BBq2nylqXB.png" />
<br /></p>
<p>3) Click on the <strong>"Edit"</strong> button on the particular domain you want to change</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655140460230/seXWwTX-w.png" alt="chrome_DPYQdxSuIj.png" />
<br /></p>
<p>4) Edit it and click on <strong>"Save"</strong> after you are done</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655140636791/WxvdLP7wp.png" alt="chrome_TEDfi57UGe.png" />
<br /></p>
<p>5) That's it! Your new Vercel subdomain is ready.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655140715703/huKIdtthQ.png" alt="chrome_OZWHvvcT39.png" />
<br /></p>
<h2 id="heading-heroku">Heroku</h2>
<p>1) Log in and click on the project whose subdomain name you wish to change</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655157715423/VwkdNCtMn.png" alt="chrome_agZCo1fhdI.png" />
<br /></p>
<p>2) After it opens up, click on <strong>"Settings"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655157812413/1JJEsDVV0.png" alt="image.png" />
<br /></p>
<p>3) Change the text in the <strong>"App name"</strong> input field to your preferred subdomain name and click on <strong>"Save"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655157994206/ueOyqIRnA.png" alt="image.png" />
<br /></p>
<p>4) Done and dusted! Your new Heroku subdomain name is set.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655142648492/y6oFJ3KPy.png" alt="chrome_xq8YLvDga0.png" />
<br /></p>
<h2 id="heading-netlify">Netlify</h2>
<p>1) Log in and click on the project whose subdomain name you want to change</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655155420388/4CuiF7x15.png" alt="chrome_VvLPxA9lyL.png" />
<br /></p>
<p>2) After it opens up, click on <strong>"Domain settings"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655155536153/aoYgwa68E.png" alt="chrome_FZPtIC48bV.png" />
<br /></p>
<p>3) Under <strong>"Custom domains"</strong>, click on <strong>"Options"</strong>, then on <strong>"Edit site name"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655155917604/2xIlozbXU.png" alt="chrome_FkfciMZhGs.png" />
<br /></p>
<p>4) Input your preferred subdomain name and click on <strong>"Save"</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655156668613/PIkaTGyS2.png" alt="chrome_4aoZVF1GHf.png" />
<br /></p>
<p>5) Just like that—you've got a new Netlify subdomain name!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1655156759010/yHtkPK9BD.png" alt="image.png" />
<br />
<br /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Whatever it is you're building, presentation is always essential. Whether your side project or your portfolio site, the domain name is the first point of contact for all who will behold whatever you've built. Random strings spat out by an algorithm do not make for a presentable domain name.</p>
<p>Hopefully, with all the info in this article, your <strong>"notorious-badlands-47642"</strong> days are over! 😉</p>
]]></content:encoded></item></channel></rss>