<?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[Thisura's Blog]]></title><description><![CDATA[Hey, I'm Thisura. I'm a full stack engineer from Sri Lanka. This blog is my little corner of the internet where I put ideas on paper. No grand ambitions, just honest writing about things I'm learning and building. If even one person finds it useful, that's enough for me.]]></description><link>https://blog.thisurathenuka.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 16:12:42 GMT</lastBuildDate><atom:link href="https://blog.thisurathenuka.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Spring Boot Unveiled: Decoding the Magic Behind Effortless Java Development]]></title><description><![CDATA[If you are a Java developer in today's world, you may have considered learning Spring Boot. Or, you might be already writing code in Spring Boot projects without having a proper understanding of how it originated. To fully understand how Spring Boot ...]]></description><link>https://blog.thisurathenuka.dev/spring-boot-unveiled-decoding-the-magic-behind-effortless-java-development</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/spring-boot-unveiled-decoding-the-magic-behind-effortless-java-development</guid><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sun, 26 Nov 2023 08:30:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1700987369612/00e0805c-6811-46d8-a32e-0f2b8c92e101.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are a Java developer in today's world, you may have considered learning Spring Boot. Or, you might be already writing code in Spring Boot projects without having a proper understanding of how it originated. To fully understand how Spring Boot works, we have to learn how Spring framework works.</p>
<p>Spring framework was initially released in 2002. How are we supposed to learn 21 years' worth of stuff?</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/CK60jbHtYaosBfmJdX/giphy.gif">https://media.giphy.com/media/CK60jbHtYaosBfmJdX/giphy.gif</a></div>
<p> </p>
<p>Yeah, it can be a daunting task. But if we can understand the key concepts, everything will start to make sense. Let me take you on a journey to explain how Spring Boot originated and its main features.</p>
<h1 id="heading-the-spring-framework">The Spring Framework</h1>
<ul>
<li><p><strong>Period</strong> - Early 2000s</p>
</li>
<li><p><strong>Why</strong> - For building enterprise Java applications</p>
</li>
<li><p><strong>Key Features :</strong></p>
<ul>
<li><p>Inversion of Control (IoC)</p>
</li>
<li><p>Aspect-Oriented Programming (AOP)</p>
</li>
<li><p>Data Access and Transaction Management</p>
</li>
</ul>
</li>
<li><p><strong>Challenges :</strong></p>
<ul>
<li><p>XML Config Hell - It heavily relied on XML configurations which led to complex setups</p>
</li>
<li><p>Boilerplate Code - Developers had to write a lot of boilerplate code to get simple things done</p>
</li>
<li><p>Complexity in integrating with other frameworks and technologies</p>
</li>
<li><p>Manual Bean(dependency) wiring</p>
</li>
<li><p>Managing Bean Lifecycle</p>
</li>
</ul>
</li>
</ul>
<p>The Spring team wanted to streamline the development process and overcome these challenges.</p>
<h1 id="heading-spring-boot-slim-turbocharged-sibling-of-spring">Spring Boot: Slim, Turbocharged sibling of Spring</h1>
<ul>
<li><p><strong>Period</strong> - 2004</p>
</li>
<li><p><strong>Why</strong> - Built on Spring framework foundations. Designed to simplify the process of building production-ready Spring applications</p>
</li>
<li><p><strong>Key Features :</strong></p>
<ul>
<li><p>Less boilerplate code. No XML configs required</p>
</li>
<li><p>Comes with sensible default configurations</p>
</li>
<li><p>Embedded web servers and built-in monitoring tools</p>
</li>
</ul>
</li>
</ul>
<p>Let me go through the key abstractions in Spring Boot.</p>
<h1 id="heading-spring-boot-starters">Spring Boot Starters</h1>
<ul>
<li><p><strong>What</strong> - Pre-configured templates with common dependencies and configurations for specific tasks or technologies</p>
</li>
<li><p><strong>Why</strong> - Simplify dependency management. Reduce the need for manual configs</p>
</li>
<li><p><strong>Examples :</strong></p>
<ul>
<li><p><code>spring-boot-starter-web</code> - For web apps (Has Spring MVC, Tomcat etc.)</p>
</li>
<li><p><code>spring-boot-starter-data-jpa</code> - For JPA-based data access (Has Hibernate, Spring Data JPA and a database driver)</p>
</li>
<li><p><code>spring-boot-starter-security</code> - For handling security concerns (Has Spring Security and related security libraries)</p>
</li>
<li><p><code>spring-boot-starter-test</code> - For testing (Has JUnit, Spring Test and related testing-related libraries)</p>
</li>
</ul>
</li>
</ul>
<h1 id="heading-auto-configuration">Auto Configuration</h1>
<ul>
<li><p><strong>What</strong> - Spring Boot automatically scans the classpath to identify libraries and automatically configures them</p>
</li>
<li><p><strong>Notes</strong> :</p>
<ul>
<li><p>We can use application properties or write a custom config class to override default configurations</p>
</li>
<li><p>We can exclude Specific auto-configurations with the <code>exclude</code> attribute.</p>
</li>
</ul>
</li>
</ul>
<h1 id="heading-embedded-web-server">Embedded Web Server</h1>
<ul>
<li><p><strong>What</strong> - Spring Boot comes with embedded web servers (Tomcat, Jetty, Undertow)</p>
</li>
<li><p><strong>Why</strong> - To eliminate the need for external server setup and simplify deployment</p>
</li>
<li><p>We can customize embedded server settings with application properties or a custom config class</p>
</li>
</ul>
<h1 id="heading-spring-boot-actuator">Spring Boot Actuator</h1>
<ul>
<li><p><strong>What</strong> - Spring Boot comes with built-in tools for monitoring and managing applications</p>
</li>
<li><p><strong>Features :</strong></p>
<ul>
<li><p>Health Endpoint - Get insights regarding the application's health</p>
</li>
<li><p>Metrics Endpoint - Expose various metrics related to performance and usage</p>
</li>
<li><p>Info Endpoint - Expose application-specific details</p>
</li>
</ul>
</li>
<li><p><strong>Notes</strong> :</p>
<ul>
<li><p>We can write custom endpoints to expose application-specific details</p>
</li>
<li><p>If we are using Actuator endpoints, we have to secure the endpoints properly.</p>
</li>
</ul>
</li>
</ul>
<h1 id="heading-conventions-over-configurations">Conventions over Configurations</h1>
<ul>
<li><p>Spring Boot has sensible default configurations that work out of the box.</p>
</li>
<li><p>Spring Boot has a standard project structure and naming conventions</p>
</li>
<li><p>Annotations like <code>@Value</code> can help to inject properties directly into components</p>
</li>
</ul>
<h1 id="heading-packaging-and-deployment">Packaging and Deployment</h1>
<ul>
<li><p>Packaging options are JAR (Java Archive) or WAR (Web Application Archive).</p>
</li>
<li><p>WAR requires an external servlet container for deployment while JAR does not need anything like that.</p>
</li>
</ul>
<hr />
<p>That's all I have for you today. I'm hoping to do an article series on Spring Boot and explain the concepts and design patterns. If you are interested, you can join our small community by following me. See you soon 🙌</p>
]]></content:encoded></item><item><title><![CDATA[How Much Do You Want It?]]></title><description><![CDATA[(Cover Image: ESPN CricInfo)
Yesterday, Australia won the ICC CWC 2023 for the 6th time, beating India in the Final. What I will talk about is not regarding the match, but what Mitchell Stark (One of the premium fast bowlers in the Australian team) s...]]></description><link>https://blog.thisurathenuka.dev/how-much-do-you-want-it</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/how-much-do-you-want-it</guid><category><![CDATA[thought-waves]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Mon, 20 Nov 2023 02:14:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1700442918412/82468520-4666-4ec1-a937-256fa48256d6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>(Cover Image: <a target="_blank" href="https://www.espncricinfo.com/series/icc-cricket-world-cup-2023-24-1367856/india-vs-australia-final-1384439/match-photo">ESPN CricInfo</a>)</p>
<p>Yesterday, Australia won the ICC CWC 2023 for the 6th time, beating India in the Final. What I will talk about is not regarding the match, but what Mitchell Stark (One of the premium fast bowlers in the Australian team) said in the mid-inning interview.</p>
<p>He said, "<em>It is not going to be an easy chase. At the end of the day, it depends on how much you want it</em>". I loved how he phrased it. Australians have always been fighters. They come to compete. This statement shows their hunger to win.</p>
<p>India was an undefeated team coming into the final. All their bowlers and batsmen have been brilliant throughout the tournament. But did Australia care? No. They weren't timid in their approach. They were fearless. They went for the kill. None of them had doubts about whether they would win or not. They just knew. That is the level of belief we all need to build in life. Whatever you do, do it wholeheartedly.</p>
<p>During the final phase of the game, I heard an Indian commentator saying "I think it is fair to say that India was beaten by the conditions and nothing else". This is another common mindset that we see among people. Blaming and worrying about the things that we have no control over is never a good approach. The Indian captain said during the toss, that he was going to bat anyway if he had won the toss. So, they got what they wanted.</p>
<p>The only way we can improve at something is by admitting our flaws. Yes, the conditions helped. But you have to admit that you were outplayed. You have to take the responsibility. Then only you will see where you can improve.</p>
<p>Australia planned and executed almost a perfect game. The field settings they set, the strategies they had for each batsman, their ground fielding, and their executions were perfect. Bringing in Maxwell in the final over of the powerplay turned out to be a genius move.</p>
<p>But that was not an accident. They have planned every bit of that wicket of Rohit Sharma. They knew Rohit would go after Maxwell. He did hit a six and a four before the dismissal. Props to Maxwell for tossing the ball up. Rohit couldn't resist. He was on 47 and wanted to just keep going. Travis Head was placed right at the edge of the 30-yard circle. He was not there to stop singles. He was placed there specifically for this miss-hit. Rohit fell for it.</p>
<p>It was a good pitch to bat on. There were no seam movements. The pitch was on the slower side. Australia utilized it perfectly. Both of the teams realized that it was not a 400 pitch. They had to revise their plans. Australia just did it better.</p>
<p>There is no doubt that India has the strongest team out of all the teams. The bowling and batting effort throughout the tournament was brilliant. But did they do their homework? Did they win the small battles on the field?</p>
<p>After Smith got out and Marnus came in, I thought India missed a trick by not attacking him right away. Marnus almost played a test match role holding his end up while Travis played his natural game at the other end. If India had got Marnus out cheaply, it would've been a much different game. <em>How much do you want it?</em></p>
<p>Coming back to my original point, we all can adopt this mindset into our lives. If you want something bad enough, you will get it. You have to be obsessed. You have to work for it. You have to build plans for it and execute them on the day. Be so good that no external factors can stop you from achieving your goals.</p>
<p>Congratulations to Pat Cummins and the Aussie team. Hard luck for India. Let's keep improving 🤘</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript's copyWithin is strange 😬]]></title><description><![CDATA[I've been writing a comprehensive guide for JavaScript array methods while learning them myself. I tried out all possible variations of each method and the methods were doing what I expected them to do, except for one.
I spent quite some time trying ...]]></description><link>https://blog.thisurathenuka.dev/javascripts-copywithin-is-strange</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/javascripts-copywithin-is-strange</guid><category><![CDATA[daily-nuggets]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Mon, 21 Aug 2023 17:17:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1692638119846/998ffe36-af3e-48bb-8efb-98f16ee15c41.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I've been writing a comprehensive guide for JavaScript array methods while learning them myself. I tried out all possible variations of each method and the methods were doing what I expected them to do, except for one.</p>
<p>I spent quite some time trying to wrap my head around the <code>copyWithin</code> method. Finally, I feel I've got the hang of it now.</p>
<p>Hey there, fellow human of the 'Not-Getting-It' realm! This article? Yep, not for the instant 'I-get-it' champs like you. This one's for us, the brave souls who embrace confusion like a warm hug. So, kick back, relax, and let's dive into the land of 'Huh? Wait, what?' together. Cheers to not getting it on the first try!</p>
<h1 id="heading-usage">Usage</h1>
<p>This method is used to copy a part of the given array and paste that copied content into another location in the same array</p>
<h1 id="heading-syntax">Syntax</h1>
<pre><code class="lang-javascript">copyWithin(target, start, end)
</code></pre>
<p><code>target (Required)</code>- Where to paste the content to</p>
<p><code>start (Optional)</code>- Where to start copying the content from <strong>(Default value - 0)</strong></p>
<p><code>end (Optional)</code>- Where to finish copying the content (Exclusive) <strong>(Default value - The length of the array)</strong></p>
<h1 id="heading-examples">Examples</h1>
<pre><code class="lang-javascript"><span class="hljs-comment">// Example 1 - With only target parameter</span>
<span class="hljs-keyword">let</span> numbers = [<span class="hljs-number">90</span>, <span class="hljs-number">88</span>, <span class="hljs-number">33</span>, <span class="hljs-number">77</span>, <span class="hljs-number">5</span>, <span class="hljs-number">66</span>]
numbers.copyWithin(<span class="hljs-number">2</span>)
<span class="hljs-comment">// The same as numbers.copyWithin(2, 0, 6)</span>
<span class="hljs-built_in">console</span>.log(numbers) <span class="hljs-comment">// [ 90, 88, 90, 88, 33, 77 ]</span>
</code></pre>
<p>This method,</p>
<ol>
<li><p>Copies the elements from indexes 0 to 6 (Exclusive), in this case, it is the whole array</p>
</li>
<li><p>Then it pastes the copied content from index 2 onwards</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-comment">// Example 2 - With start and end parameters</span>
<span class="hljs-keyword">let</span> numbers = [<span class="hljs-number">15</span>, <span class="hljs-number">18</span>, <span class="hljs-number">22</span>, <span class="hljs-number">40</span>, <span class="hljs-number">65</span>, <span class="hljs-number">35</span>, <span class="hljs-number">58</span>]
numbers.copyWithin(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">6</span>)
<span class="hljs-built_in">console</span>.log(numbers) <span class="hljs-comment">// [15, 18, 40, 65, 35, 35, 58]</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692636353244/9d2005db-a4b2-4911-b187-34eee8db5969.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Example 3</span>
<span class="hljs-keyword">let</span> numbers = [<span class="hljs-number">15</span>, <span class="hljs-number">18</span>, <span class="hljs-number">22</span>, <span class="hljs-number">40</span>, <span class="hljs-number">65</span>, <span class="hljs-number">35</span>, <span class="hljs-number">58</span>]
numbers.copyWithin(<span class="hljs-number">5</span>, <span class="hljs-number">3</span>, <span class="hljs-number">6</span>)
<span class="hljs-built_in">console</span>.log(numbers) <span class="hljs-comment">// [15, 18, 22, 40, 65, 40, 65]</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692636823774/75d4643b-fc63-4be9-a68c-b6d0729cfd62.png" alt class="image--center mx-auto" /></p>
<p>As you can see, this method <strong>never extends the array</strong>.</p>
<p>If there is not enough space to paste all the copied elements, it will just paste what it can and ignore the rest.</p>
<p><code>copyWithin</code>is in the category of array modification methods. I will provide a comprehensive categorized guide for all the JS Array methods in an upcoming article.</p>
<hr />
<p>Thank you for diving into the article! If you found it as captivating as a page-turner, consider dropping a virtual high-five with a like, leaving your thoughts in the comments, and embarking on a journey with me for more mind-enriching content. Until we cross paths again, take care and keep your curiosity alive! 🚀✨</p>
]]></content:encoded></item><item><title><![CDATA[Don't misuse JavaScript Array map]]></title><description><![CDATA[I've been using the JavaScript Array map() function whenever I needed to iterate an array and manipulate it. But today I learned that even though it gets the job done, it has some disadvantages.
Usage
map is a higher-order function in JavaScript sinc...]]></description><link>https://blog.thisurathenuka.dev/dont-misuse-javascript-array-map</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/dont-misuse-javascript-array-map</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[daily-nuggets]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 19 Aug 2023 18:25:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1692469390592/e4228147-a3a3-43e5-96a0-04dcf67bb9c4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I've been using the JavaScript Array <code>map()</code> function whenever I needed to iterate an array and manipulate it. But today I learned that even though it gets the job done, it has some disadvantages.</p>
<h2 id="heading-usage">Usage</h2>
<p><code>map</code> is a higher-order function in JavaScript since it takes a function as its argument.</p>
<p><code>Array.prototype.map(callbackFn)</code></p>
<p>The <code>map</code> function does 3 things.</p>
<ol>
<li><p>It creates a new array</p>
</li>
<li><p>Then, it applies a given function to each element of an existing array</p>
</li>
<li><p>Then, that updated element is pushed into the new array and returned</p>
</li>
</ol>
<h2 id="heading-scenarios-to-be-aware-of">Scenarios to be aware of</h2>
<p>Here are the reasons why you should refrain from using the <code>map</code> function if you are not going to utilize all its benefits.</p>
<h3 id="heading-performance-overhead">Performance Overhead</h3>
<p>The <code>map</code> function creates a new array and applies the callback function to all the elements. This can lead to unnecessary memory usage and performance overhead, especially if the array is larger.</p>
<p>If you just want to iterate through the array and you are not going to use the returned array, stick with <code>for</code> loops or <code>forEach</code> loops.</p>
<h3 id="heading-early-termination">Early Termination</h3>
<p>If you have a particular condition where you need to break out from the loop, you can't do that if you are using the <code>map</code> function</p>
<p>Here is how you would do it in a simple for loop.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> num <span class="hljs-keyword">of</span> numbers) {
  <span class="hljs-keyword">if</span> (sum &gt; <span class="hljs-number">10</span>) {
    <span class="hljs-keyword">break</span>; <span class="hljs-comment">// Early termination</span>
  }
  sum += num;
}
</code></pre>
<p>As soon as the value <code>sum</code> exceeds 10, the loop will be stopped.</p>
<p>There is no way to do this when we are using the map function. The closest thing that is possible is to skip over that particular element.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
<span class="hljs-keyword">const</span> modifiedNumbers = numbers.map(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> {
  <span class="hljs-keyword">if</span> (sum &gt; <span class="hljs-number">10</span>) {
    <span class="hljs-keyword">return</span> num; <span class="hljs-comment">// Early return, effectively skipping processing of the remaining elements</span>
  }
  sum += num;
  <span class="hljs-keyword">return</span> num; <span class="hljs-comment">// Continue processing for other elements</span>
});
</code></pre>
<h3 id="heading-no-side-effects">No Side Effects 🥺</h3>
<p>The <code>map</code> function <strong>should not be used</strong> to perform side effects like updating external variables. This is against functional programming paradigms that the <code>map</code> function is a part of. The primary purpose of the <code>map</code> function is to transform data in the current array and create a new array.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;

<span class="hljs-keyword">const</span> doubledNumbers = numbers.map(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> {
  <span class="hljs-keyword">const</span> doubled = num * <span class="hljs-number">2</span>;
  sum += doubled; <span class="hljs-comment">// Modifying external variable</span>
  <span class="hljs-keyword">return</span> doubled;
});

<span class="hljs-built_in">console</span>.log(doubledNumbers); <span class="hljs-comment">// [2, 4, 6, 8, 10]</span>
<span class="hljs-built_in">console</span>.log(sum); <span class="hljs-comment">// 30 (Sum of doubled numbers)</span>
</code></pre>
<p>Even though this gets the job done, this can make the lives of other programmers harder. This will make the codebase harder to maintain over time and reduce the readability of the code.</p>
<p>Instead of using the <code>map</code> function, stick with a simple <code>forEach</code> loop.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;

numbers.forEach(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> {
  <span class="hljs-keyword">const</span> doubled = num * <span class="hljs-number">2</span>;
  sum += doubled; <span class="hljs-comment">// Modifying external variable</span>
});

<span class="hljs-built_in">console</span>.log(sum); <span class="hljs-comment">// 30 (Sum of doubled numbers)</span>
</code></pre>
<hr />
<p>Thank you for diving into the article! If you found it as captivating as a page-turner, consider dropping a virtual high-five with a like, leaving your thoughts in the comments, and embarking on a journey with me for more mind-enriching content. Until we cross paths again, take care and keep your curiosity alive! 🚀✨</p>
]]></content:encoded></item><item><title><![CDATA[Be Afraid and Do It Anyway]]></title><description><![CDATA[Disclaimer: Please be advised that this article may contain explicit language and reader discretion is advised.

There may be a lot of things in life that we are afraid of. We always procrastinate facing our fears. Everyone knows that we should get o...]]></description><link>https://blog.thisurathenuka.dev/be-afraid-and-do-it-anyway</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/be-afraid-and-do-it-anyway</guid><category><![CDATA[thought-waves]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Tue, 11 Jul 2023 02:45:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689042005035/00db291c-ba18-491c-8ed1-6bbf2a78d19b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>Disclaimer: Please be advised that this article may contain explicit language and reader discretion is advised.</p>
</blockquote>
<p>There may be a lot of things in life that we are afraid of. We always procrastinate facing our fears. Everyone knows that we should get out and expand our comfort zone. Less people follow along with it. Yes, It is not easy. It is not supposed to be easy.</p>
<h2 id="heading-whats-the-worst-thing-that-could-happen">What's the worst thing that could happen?</h2>
<p>Usually, most of the fears you have are not bad as you think they are. Let's take public speaking as an example.</p>
<p><img src="https://media.giphy.com/media/FDITqxKuHCIp1T5Kjf/giphy.gif" alt="Dwight Public Speaking" class="image--center mx-auto" /></p>
<p>"What's the worst thing that could happen to you?"</p>
<p>"People will laugh at me"</p>
<p>Well, why do you care so much about what anyone else thinks? You have limited fucks to give in life. You can't give a fuck about what everyone thinks. Prioritize who is important to you. Prioritize the people who want to see you succeed.</p>
<h2 id="heading-you-might-be-missing-out-on-something-great">You might be missing out on something great</h2>
<p>We always visualize ourselves screwing up. Why don't we switch it around and think about the other side of the spectrum? Learning public speaking right now will boost your confidence. People will respect you more. You'll get your dream job. There are infinite possibilities.</p>
<p>Do you want to miss out on all that because of the potential of some fucker in the audience laughing at you? Think about it. Visualize what you will be missing out on.</p>
<h2 id="heading-one-baby-step-at-a-time">One Baby Step at a Time</h2>
<p>If you are a fan of the TV series F.R.I.E.N.D.S., you should remember how Chandler freaked out on his wedding day.</p>
<p><img src="https://media.giphy.com/media/SSco1wrAMYuw7slZPA/giphy.gif" alt="Chandler Freaking Out" class="image--center mx-auto" /></p>
<p>And do you remember how Ross helped him out? That's right. One step at a time. Going home and getting a shower doesn't sound that hard.</p>
<p>If you tend to freak out when you see the big picture. Break it down into smaller manageable steps.</p>
<p>If you find yourself being lazy about going to the Gym,</p>
<ul>
<li><p>Put on your gym clothes and that's it.</p>
</li>
<li><p>Just step outside the house and that is all.</p>
</li>
<li><p>Take the bus or start walking towards the Gym and that's all.</p>
</li>
<li><p>Just go inside the gym and that's it</p>
</li>
<li><p>Since you're already in the gym, might as well just do the treadmill for a few minutes</p>
</li>
</ul>
<p>When we keep telling ourselves that all we have to do is this small thing and that is it, our stupid brain falls for it. I don't know how it happens, but it works all the time.</p>
<p>You can apply this to most of the things in life. If you have <a target="_blank" href="https://www.masterclass.com/articles/what-is-writers-block-how-to-overcome-writers-block-with-step-by-step-guide-and-writing-exercises">writer's block</a> and can't get yourself to write anything, just open the editor and write one sentence. That doesn't sound that hard, does it? More often than not you will find yourself writing multiple paragraphs after that.</p>
<p>Getting started is the hardest part of doing something. Break it down. Make it sound less intimidating. Works like a charm.</p>
<h2 id="heading-54321and-go">5..4..3..2..1..and Go</h2>
<p>You may have already heard about <a target="_blank" href="https://www.theceomagazine.com/business/management-leadership/the-5-second-rule/#:~:text=%E2%80%9CThe%20moment%20you%20feel%20yourself,comfort%20zone%2C%E2%80%9D%20she%20adds.">the 5-second rule from Mel Robbins</a>.</p>
<p><img src="https://media.giphy.com/media/I4Up7oqHnEJ2IGOAud/giphy.gif" alt="Mel Robbins Saying Hi" class="image--center mx-auto" /></p>
<p>Whenever you find yourself overthinking something, you can use this rule to take action. According to Mel, all we have is a 5-second window to go from idea to action. Otherwise, our brain will step in and talk us out of it.</p>
<p>Just count to yourself, 5..4..3..2..1 and do the thing.</p>
<p>Can't get yourself out of bed in the morning? 5..4..3..2..1 and go.</p>
<p>Want to talk to a girl at a party? 5..4..3..2..1 and go up to her and just say hi.</p>
<p>You can use this for most of the things in life. If you are interested in learning about the science behind it, check out <a target="_blank" href="https://www.youtube.com/watch?v=2n41e9su3fM">this video</a> on YouTube.</p>
<h2 id="heading-be-afraid-and-do-it-anyway">Be Afraid and Do It Anyway</h2>
<p>One of the best life advice I've ever heard came from Missy Cooper from the TV series, Young Sheldon. Sheldon was a kid and he was about to graduate from high school and go to college. He was afraid of how things would change.</p>
<p><img src="https://media.giphy.com/media/l2QE8iBYB9bUIf69O/giphy.gif" alt="Sheldon Freaking Out" class="image--center mx-auto" /></p>
<p>He could not sleep the day before graduation. His sister, Missy was laying on the other bed in the room.</p>
<blockquote>
<p>Sheldon: "So you were scared ?"</p>
<p>Missy: "Yeah"</p>
<p>Sheldon: "So what do we do ?"</p>
<p>Missy: "I guess be scared and do it anyways"</p>
</blockquote>
<p>This conversation helped Sheldon overcome his fear. He graduated the next day and he thanked Missy in his graduation speech.</p>
<p>Change is coming whether we like it or not. Don't try to resist it. Live in the moment and embrace change when it comes.</p>
<hr />
<p>If you enjoyed reading the article, I would appreciate it if you could show your support by liking and sharing it. If you believe your friends would also find it interesting, please consider sharing it with them. 🙌</p>
]]></content:encoded></item><item><title><![CDATA[Demystifying CORS - Everything You Need to Know]]></title><description><![CDATA[If you’re a web developer, chances are you’ve come across the pesky CORS error. But fear not! This article is here to help fellow developers understand and master the CORS policy. I’ll break it down for you in simple terms so you can tackle this erro...]]></description><link>https://blog.thisurathenuka.dev/demystifying-cors-everything-you-need-to-know</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/demystifying-cors-everything-you-need-to-know</guid><category><![CDATA[webdev]]></category><category><![CDATA[CORS]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Wed, 01 Mar 2023 03:47:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1677642394577/096d8e5f-03a4-457b-8214-e78469d88c8f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you’re a web developer, chances are you’ve come across the pesky CORS error. But fear not! This article is here to help fellow developers understand and master the CORS policy. I’ll break it down for you in simple terms so you can tackle this error with ease. So, let’s jump right in and unravel the mysteries of CORS!</p>
<h1 id="heading-what-is-the-same-origin-policy">What is the Same-Origin Policy?</h1>
<p>The Same-Origin Policy is like a rule that web browsers follow to keep you safe on the internet.</p>
<p>It says that if a web page from one website tries to do something on a different website, like read information or send data, the web browser won’t let it happen. It’s like a security guard that stops people from going where they’re not supposed to.</p>
<p>This is important because it helps protect your personal information and keeps you safe from bad things on the internet. Imagine if anyone could read your emails or see your bank account information just by going to a website! The Same-Origin Policy helps prevent that from happening.</p>
<h1 id="heading-what-is-cors">What is CORS?</h1>
<p>Cross-Origin Resource Sharing or CORS is a way for web pages to ask permission from a different website to use its information.</p>
<p>Let’s say you want to view some pictures on a website called “A”. But the pictures are stored on a different website called “B”. Normally, your web browser won’t show you the pictures because of the Same-Origin Policy.</p>
<p>But with CORS, website “A” can send a special message called a “CORS request” to website “B”. This message asks website “B” if it’s okay for website “A” to see the pictures. If website “B” says it’s okay, then your web browser will show you the pictures from website “B” on website “A”.</p>
<p>CORS helps web pages work together and share information safely, like when you share your toys with your friends. It’s important because it allows websites to work together and show you the information you want to see.</p>
<h1 id="heading-what-are-preflight-requests">What are preflight requests?</h1>
<p>Preflight requests are like asking for permission before doing something.</p>
<p>Let’s say a website wants to share information with another website using CORS, but the information is sensitive and needs extra protection. The website will send a special message called a “preflight request” before sending the actual message.</p>
<p>The preflight request asks the other website if it’s okay to send sensitive information. It’s like asking your parents if it’s okay to go to a friend’s house for a sleepover.</p>
<p>The other website will then send a message back saying if it’s okay to send the information or not. If it’s okay, the original website will send the sensitive information, but if it’s not okay, the information won’t be sent.</p>
<p>Preflight requests help keep your information safe on the internet by making sure that websites only send and receive information when it’s safe to do so. It’s like checking with your parents before doing something that might be dangerous.</p>
<h1 id="heading-what-are-cors-headers">What are CORS headers?</h1>
<p>CORS headers are messages that websites use to talk to each other and decide if it’s safe to share information. Different kinds of CORS headers have different jobs, just like how different tools have different jobs in a toolbox.</p>
<p>Here are a few examples of different CORS headers and what they do:</p>
<ol>
<li><p>Access-Control-Allow-Origin: This CORS header tells your web browser which websites are allowed to see the information. It’s like telling your friends which toys they can play with.</p>
</li>
<li><p>Access-Control-Allow-Methods: This CORS header tells your web browser which kinds of actions it can take with the information, like reading or editing. It’s like telling your friends which games they can play with the toys.</p>
</li>
<li><p>Access-Control-Allow-Credentials: This CORS header tells your web browser if it’s okay to send personal information, like passwords. It’s like telling your friends if it’s okay to come into your room or not.</p>
</li>
<li><p>Access-Control-Allow-Headers: This CORS header tells your web browser which kinds of information it can share, like text or pictures. It’s like telling your friends what kind of snacks they can have.</p>
</li>
</ol>
<p>By using these different CORS headers, websites can make sure that they’re only sharing information that’s safe to share, and keeping your personal information secure. It’s like making sure that only your trusted friends can come over to play, and that they know the rules for playing with your toys.</p>
<h1 id="heading-how-do-i-handle-cors-errors">How do I handle CORS errors?</h1>
<p>Picture this — you’re on a website and you spot some juicy information on another website that you’d love to get your hands on. But before you can access it, your browser needs to ask for permission. It sends a preflight request to check if the other website will let you use its resources. If the answer is no, you’ll encounter the dreaded CORS error, blocking your request.</p>
<p>There are a few different types of CORS errors, but they all mean the same thing: you can’t access the information or resources you want. Here are the most common CORS errors that you will encounter.</p>
<ul>
<li><p>Access-Control-Allow-Origin: This error means that the website you’re trying to access doesn’t allow other websites to use its resources.</p>
</li>
<li><p>Access-Control-Allow-Headers: This error means that the website you’re trying to access doesn’t allow you to use certain headers in your request.</p>
</li>
<li><p>Access-Control-Allow-Methods: This error means that the website you’re trying to access doesn’t allow you to use certain methods, like GET or POST, to access its resources.</p>
</li>
</ul>
<p>If you run into a CORS error, don’t worry! There are ways to handle it. One way is to contact the owner of the website you’re trying to access and ask them to allow other websites to use its resources. Another way is to use a proxy server, which acts as a middleman between you and the website you’re trying to access.</p>
<p>If you’d like to read more about all the different CORS errors, you can refer to the MDN Docs article from <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors">here</a>.</p>
<h1 id="heading-what-are-the-cors-best-practices">What are the CORS Best Practices?</h1>
<p>To ensure your website is secure and functional, it’s important to follow some best practices when working with CORS.</p>
<ol>
<li><p>Include the necessary CORS headers in your server’s response: When a browser makes a cross-origin request, the server being accessed must include specific response headers to permit the request. Make sure your server includes the appropriate CORS headers such as Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers.</p>
</li>
<li><p>Only allow access to necessary resources: To minimize the risk of unauthorized access, only allow cross-origin access to necessary resources. Avoid allowing access to sensitive information or resources unless it’s required.</p>
</li>
<li><p>Use SSL/TLS encryption: Use SSL/TLS encryption to ensure that any data being transmitted is secure. This can help prevent unauthorized interception of data.</p>
</li>
<li><p>Set appropriate CORS configuration: Set up CORS configuration based on your website’s requirements. For example, if your website has a public API that should be accessible to third-party websites, set up CORS to allow cross-origin requests from those specific domains.</p>
</li>
<li><p>Monitor CORS requests: Monitor cross-origin requests to your website to identify any unusual or potentially malicious activity. Implement logging and monitoring tools to detect any unauthorized access attempts.</p>
</li>
</ol>
<p>By following these best practices, you can help ensure that your website is secure and functional while allowing cross-origin requests as needed.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Understanding and being able to handle the Cross-Origin Resource Sharing (CORS) policy is crucial for every web developer. During my early days in web development, I had to face the dreadful CORS error which led me to waste so much time trying out numerous solutions from Stack Overflow without truly comprehending the concept. But, now that I have gained ample knowledge about CORS, I can confidently say that you don’t have to suffer the same fate as I did. So, take the time to understand CORS and save yourself from the hassle of going through a maze of solutions.</p>
<p>Thank you so much for taking the time to read my article! My utmost priority was to simplify complex concepts, and I hope I’ve achieved that. If you found my article informative and useful, please drop a comment below and don’t forget to follow me for more articles like this. Oh, and spread the word by sharing it with your friends and colleagues, they might thank you for it!</p>
]]></content:encoded></item><item><title><![CDATA[Demystifying DNS - Everything You Need to Know]]></title><description><![CDATA[The article’s objective is to cover all the key information about the Domain Name System (DNS). Everyone interested in learning more about DNS should read this article. I will try to explain what you need to know in layman’s terms. Without further ad...]]></description><link>https://blog.thisurathenuka.dev/demystifying-dns-everything-you-need-to-know</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/demystifying-dns-everything-you-need-to-know</guid><category><![CDATA[dns]]></category><category><![CDATA[dnssec]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Mon, 27 Feb 2023 10:27:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1677492943630/f575f489-1665-4484-9a60-d02626c948de.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The article’s objective is to cover all the key information about the Domain Name System (DNS). Everyone interested in learning more about DNS should read this article. I will try to explain what you need to know in layman’s terms. Without further ado, let’s get into it.</p>
<h1 id="heading-what-is-dns-and-why-is-it-important">What is DNS and why is it important?</h1>
<p>DNS is like a big phone book for the internet. You know how you have a phone book at home with all your friends’ phone numbers and addresses? Well, DNS is like that, but for websites.</p>
<p>When you want to go to a website, you type in the website’s name, like “<a target="_blank" href="http://google.com">google.com</a>". DNS takes that name and looks it up in the phone book to find the website’s “phone number”, which is called an IP address. Then, DNS tells your computer the IP address, and your computer uses that to find the website and show it to you.</p>
<p>DNS is essential because it helps us find websites easily and quickly, without having to remember a bunch of numbers. It’s like having an astute helper who knows where all the websites are and how to get to them!</p>
<h1 id="heading-what-is-the-hierarchy-of-dns">What is the hierarchy of DNS?</h1>
<p>Remember how I explained that DNS is like a big phone book for the internet? Well, it’s not just one big phone book. It’s actually lots of phone books, all working together in a big chain.</p>
<p>At the very top of the chain is something called the “root” server. This server lists all the top-level domains (TLDs), like .com, .org, .net, and so on.</p>
<p>When you type in a website name, like “<a target="_blank" href="http://google.com">google.com</a>", your computer goes to the next level of the chain, which is the server for the “.com” top-level domain. That server has a list of all the websites that end in “.com”, and it can tell your computer where to find “<a target="_blank" href="http://google.com">google.com</a>".</p>
<p>Then, your computer goes to the next level of the chain, which is the server for “<a target="_blank" href="http://google.com">google.com</a>". That server has a list of all the pages on the Google website, and it can tell your computer where to find the page you’re looking for.</p>
<p>This chain of servers is called the “DNS hierarchy”, and it helps your computer find the right website quickly and easily. It’s like a big team of helpers, each one passing along the information to the next one until you get to where you want to go.</p>
<p>Here is a simple diagram of the DNS hierarchy for you to get an idea.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1677492978138/2e1eaf5d-1fce-482c-997c-1b25888308b1.png" alt="DNS Heirarchy" class="image--center mx-auto" /></p>
<p>So, that’s how DNS hierarchy works! It’s a big chain of servers, each one responsible for a different part of the internet phone book, all working together to help us find websites.</p>
<h1 id="heading-what-are-the-dns-server-types">What are the DNS server types?</h1>
<p>DNS servers are like special computers that help to make the internet work. There are two main types of DNS servers.</p>
<ol>
<li><p>authoritative DNS servers</p>
</li>
<li><p>recursive DNS servers</p>
</li>
</ol>
<p>An authoritative DNS server is like a phone book for the internet. It stores information about domain names and their corresponding IP addresses. When someone wants to visit a website, their computer asks the authoritative DNS server for the IP address that corresponds to the domain name they’re trying to visit.</p>
<p>A recursive DNS server is like a helper for your computer. When your computer wants to visit a website, it asks the recursive DNS server for the IP address that corresponds to the domain name. The recursive DNS server then goes and asks the authoritative DNS server for the information. Once it gets the information, it sends it back to your computer, which can then connect to the website.</p>
<p>Recursive DNS servers are important because they can help to speed up your internet experience. They store information about domain names and their corresponding IP addresses in a special cache so that they can quickly give you the information you need without having to go all the way to the authoritative DNS server every time.</p>
<h1 id="heading-what-are-dns-records">What are DNS records?</h1>
<p>DNS records are like little notes that tell your computer where to find a website. They are a part of the DNS system, which helps your computer find the right website when you type in a name like “<a target="_blank" href="http://google.com">google.com</a>".</p>
<p>There are different types of DNS records, each one with a different job. Here are some of the most common ones:</p>
<ul>
<li><p>A (Address) record: This is the most important DNS record because it tells your computer the IP address of the web server hosting a website. When you type in a website name like “<a target="_blank" href="http://google.com">google.com</a>", your computer looks up the A record for that domain name to find the IP address of the web server.</p>
</li>
<li><p>CNAME (Canonical Name) record: This record is like a shortcut. It tells your computer to look up the IP address for one domain name, but use the website content from another domain name. For example, the CNAME record for “<a target="_blank" href="http://test.google.com">test.google.com</a>” might tell your computer to use the website content from “<a target="_blank" href="http://google.com">google.com</a>". This record is usually used in place of an A record. All CNAME records always point to a domain, not an IP address.</p>
</li>
<li><p>MX (Mail Exchange) record: This record tells your computer where to send an email for a domain name. It’s used by email servers to find the correct destination for incoming email messages.</p>
</li>
<li><p>TXT (Text) record: This record is like a note that can contain any kind of text information. It’s often used to provide additional information about a domain name, such as ownership or security details.</p>
</li>
</ul>
<p>These are just a few examples of the types of DNS records that exist. Each one has a specific job to help your computer find the right website or send an email to the right place. DNS records are like little helpers that work together to make sure everything on the internet runs smoothly!</p>
<h1 id="heading-what-is-dns-propagation-and-caching">What is DNS propagation and caching?</h1>
<p>When you type in a website name like “<a target="_blank" href="http://google.com">google.com</a>", your computer uses the DNS system to find the IP address of the web server hosting that website. But did you know that the DNS system can take some time to update with new information?</p>
<p>This is because of something called DNS propagation. When a change is made to the DNS records for a domain name, it can take some time for that change to be propagated, or spread out, to all of the DNS servers around the world. This means that some people might still see the old information for a little while, even after a change has been made.</p>
<p>Another thing to know about DNS is that your computer doesn’t always look up the DNS information from scratch every time you visit a website. Instead, it stores the information in a cache or a temporary storage area, so it can access it more quickly the next time you visit that website.</p>
<p>DNS caching is helpful because it makes your internet experience faster and smoother. Your computer doesn’t have to spend time looking up the DNS information every time you visit a website. Instead, it can use the information it already has stored in the cache.</p>
<p>However, DNS caching can also cause problems when changes are made to DNS records. Because your computer is using the cached information, it might not see the updated information right away. This is another reason why DNS propagation can take some time. You can <a target="_blank" href="%5Bhttps://www.keycdn.com/support/dns-cache%5D(https://www.keycdn.com/support/dns-cache)">flush the DNS cache</a> to get rid of this issue.</p>
<p>So, DNS propagation and caching are two things that affect how quickly and accurately your computer can find the websites you’re looking for. Sometimes it might take a little bit of time for everything to update, but don’t worry — your computer and the DNS system are always working hard to make sure you can access the internet quickly and easily!</p>
<h1 id="heading-what-are-dns-security-and-dnssec">What are DNS security and DNSSEC?</h1>
<p>DNS security is important because it helps to make sure that the DNS system is working correctly and that you’re truly connecting to the website you think you are. Someone could try to trick the DNS system, either by changing the DNS records for a website or by creating a fake website that looks like the real one.</p>
<p>One way that DNS security is improved is through something called DNSSEC. This is a system that adds extra security information to the DNS records for a website. When your computer looks up the DNS information for a website that has DNSSEC, it can check the security information to make sure that the information it’s getting is really from the website it thinks it is.</p>
<p>DNSSEC works by adding a digital signature to the DNS records for a website. This signature is like a special code that proves that the information is real and hasn’t been tampered with. Your computer can check the signature to make sure that it’s connecting to the real website and not a fake one.</p>
<p>DNSSEC is a very important part of DNS security because it helps to protect against attacks that try to trick the DNS system. With DNSSEC, you can be more confident that the websites you’re visiting are the ones you intend to visit, and that your internet experience is secure and trustworthy.</p>
<h1 id="heading-how-does-dns-load-balancing-work">How does DNS load balancing work?</h1>
<p>Sometimes, when lots of people want to visit a website, the server that hosts that website can get overwhelmed and stop working properly. This can make the website slow or even cause it to crash! To prevent this from happening, website owners can use something called DNS load balancing.</p>
<p>DNS load balancing is when a website owner sets up multiple servers to host their website. When someone tries to visit the website, the DNS system can choose which server to send them to. This helps spread out the traffic and prevent any server from getting too overwhelmed.</p>
<p>One way that the DNS system can choose which server to send someone to is by using something called <strong>round-robin DNS</strong>. Round-robin DNS is when the DNS system rotates through a list of IP addresses for the different servers. So, if three servers are hosting a website, the DNS system might send the first person who tries to visit the website to the first server, then send the second person to the second server, and so on.</p>
<p>Round-robin DNS is a simple and effective way to do DNS load balancing. By spreading out the traffic among multiple servers, website owners can ensure that their website stays fast and responsive, even when lots of people are trying to visit it simultaneously.</p>
<h1 id="heading-how-do-i-troubleshoot-dns">How do I troubleshoot DNS?</h1>
<p>Sometimes, things can go wrong with DNS servers. When this happens, you can use the following checklist of troubleshooting techniques to use to figure out what’s going on.</p>
<ol>
<li><p>Check your internet connection: Before you do anything else, make sure that your internet connection is working properly. If your internet connection is down, you won’t be able to access any websites, no matter what you do!</p>
</li>
<li><p>Try a different device: If you’re having trouble accessing a website on one device, try accessing it on a different device. This can help you figure out whether the problem is with the website or with your device.</p>
</li>
<li><p>Check your DNS settings: Make sure that your device is set up to use the correct DNS servers. If you’re not sure what the correct DNS servers are, you can try using Google’s DNS servers (8.8.8.8 and 8.8.4.4).</p>
</li>
<li><p>Clear your DNS cache: Sometimes, your device’s DNS cache can get corrupted. When this happens, you might not be able to access certain websites. To fix this, you can try clearing your device’s DNS cache.</p>
</li>
<li><p>Check the website’s DNS records: If you’re having trouble accessing a particular website, it could be because there’s something wrong with the website’s DNS records. You can use a special tool called a DNS lookup tool to check the website’s DNS records and see if there are any problems.</p>
</li>
</ol>
<h1 id="heading-conclusion">Conclusion</h1>
<p>In conclusion, DNS is a critical component of the internet infrastructure that enables us to access websites and services by their domain names. Understanding the hierarchy of DNS, different types of DNS servers, DNS records, and DNS security can help us manage and troubleshoot DNS effectively. Additionally, learning about DNS propagation, caching, and load balancing can improve website performance and availability.</p>
<p>Finally, thank you for taking the time to read my article. I tried my best to break the concepts down into simple terms. If you found my article helpful, please make to share it with your friends and colleagues.</p>
]]></content:encoded></item><item><title><![CDATA[How I Became a Software Engineer]]></title><description><![CDATA[Hi Guys,
I am Thisura Thenuka. I'm a 23-year-old from Sri Lanka and I work as a Full Stack Engineer in a Software Company. I've been working in the industry for almost 3 years now.
I'm going to share with you today how I came to be a software enginee...]]></description><link>https://blog.thisurathenuka.dev/how-i-became-a-software-engineer</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/how-i-became-a-software-engineer</guid><category><![CDATA[thought-waves]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Tue, 30 Aug 2022 17:48:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661881494543/vP0mqHvZz.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi Guys,</p>
<p>I am Thisura Thenuka. I'm a 23-year-old from Sri Lanka and I work as a Full Stack Engineer in a Software Company. I've been working in the industry for almost 3 years now.</p>
<p>I'm going to share with you today how I came to be a software engineer and what inspired me to do it.</p>
<h1 id="heading-school-life">School Life</h1>
<p>I started learning Information Technology as a subject in school when I was 11. At the time, I was learning about flow charts, logic gates, networks and so on. The first programming language I learned was Visual Basic. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661444195042/1u2EbcPIX.png" alt="visual-basic.png" class="image--center mx-auto" /></p>
<p>During a tuition lesson I took to study IT, programming became my absolute obsession. I found the process of attempting to solve challenging programming problems to be quite fascinating. I think a big part of how I became a software engineer was due to the young geeky man inside of me.</p>
<h1 id="heading-uni-life">Uni Life</h1>
<p>After 14 years of education, I learned about a scholarship program that enables me to get a degree in software engineering while working full-time for a tech company. After an exam and an interview, I got selected for the scholarship program.</p>
<p>I'm in my third year of university right now. I was fortunate to have a group of friends who were really encouraging. We enjoyed working on new projects while attending events, parties, and hackathons.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/IwAZ6dvvvaTtdI8SD5/giphy.gif">https://media.giphy.com/media/IwAZ6dvvvaTtdI8SD5/giphy.gif</a></div>
<h1 id="heading-work-life">Work Life</h1>
<p>I had the honour of working with great developers and it was quite inspiring to see how they went about doing their things. I didn't really understand how to function in a professional setting when I first joined. My senior colleagues were incredibly helpful and considerate, teaching me a lot about managing daily interactions, documentation, coding standards, bug fixes, effort estimations, and many more.</p>
<p>Even though most of them are working in different companies now, I'm really grateful for the things they thought me.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661879477453/uelrKDkfo.jpg" alt="fight-for-you.jpg" class="image--center mx-auto" /></p>
<h1 id="heading-future">Future</h1>
<p>I still have two years to go in both my internship and my degree program. I intend to fully develop my portfolio over this time and network with new professionals in the field. Not many of my projects have been finished to the point of public display. I plan to concentrate more on creating projects and contributing to open-source projects.</p>
<p>Thank you for reading my article. This article was written as the Week 1 article in <strong>4 Articles in 4 Weeks - Hashnode Writeathon</strong>. If you have any suggestions for me to try out in order to build a great portfolio, please make sure to drop a comment 🥳👋</p>
]]></content:encoded></item><item><title><![CDATA[Add Redux to your React app in 6 Simple Steps]]></title><description><![CDATA[Redux is a predictable state container for JavaScript apps. 
Do I need to use Redux in my React app?
It depends.
If your app is simple and works with a minimal number of states, there is no need to add redux to your app.
If your app is complex and ha...]]></description><link>https://blog.thisurathenuka.dev/add-redux-to-your-react-app-in-6-simple-steps</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/add-redux-to-your-react-app-in-6-simple-steps</guid><category><![CDATA[React]]></category><category><![CDATA[Redux]]></category><category><![CDATA[ReactHooks]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 20 Aug 2022 11:50:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660995577613/M8f-0JyxL.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Redux is a predictable state container for JavaScript apps. </p>
<h1 id="heading-do-i-need-to-use-redux-in-my-react-app">Do I need to use Redux in my React app?</h1>
<p>It depends.</p>
<p>If your app is simple and works with a minimal number of states, there is no need to add redux to your app.</p>
<p>If your app is complex and has a lot of stuff going on, you should consider adding redux to your app. It will provide a clean and simple structure to handle states and improve the longevity of the code.</p>
<h1 id="heading-redux-vs-usecontext-and-usereducer">Redux vs useContext and useReducer</h1>
<p>By utilizing React's useContext and useReducer hooks, we can provide the same functionality as Redux. The boilerplate code is significantly less, and it is much simpler.</p>
<p>But it's crucial that you understand how Redux functions because most software companies already use it in their projects, and it will undoubtedly help you in your next interview.</p>
<h1 id="heading-redux-basic-concepts">Redux Basic Concepts</h1>
<p>There are a few simple concepts you should understand before adding redux to your react app.</p>
<h2 id="heading-store">Store</h2>
<p>The Redux Store holds the state of your app. Your app is always subscribed to the store. But your app can't <strong>directly</strong> change the state in the store.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660971958044/Jmak6_es4.png" alt="Redux Store.drawio.png" class="image--center mx-auto" /></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/4FeKMrvWvPiBN9BMZO/giphy.gif">https://media.giphy.com/media/4FeKMrvWvPiBN9BMZO/giphy.gif</a></div>
<p>This is where actions and action creators come in.</p>
<h2 id="heading-action-types-actions-and-action-creators">Action Types, Actions and Action Creators</h2>
<p>Action types are constants that are used to define the values used for the type property of Actions.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> ADD_TASK = <span class="hljs-string">"ADD_TASK"</span>;
</code></pre>
<p>An action is any object with a <strong>type</strong> property. Actions help us describe what needs to happen.</p>
<pre><code class="lang-javascript">{
    <span class="hljs-attr">type</span>: ADD_TASK
}
</code></pre>
<p>An action creator is simply a JS function that returns an action.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> addTask = <span class="hljs-function">(<span class="hljs-params">task</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">type</span>: ADD_TASK,
        <span class="hljs-attr">payload</span>: task,
    };
};
</code></pre>
<p>The only thing your app can do is to "<strong>dispatch</strong>" actions. Dispatch is a method provided by the react-redux library's <code>useDispatch</code> hook. I'll get into this later when we implement the code.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660979879845/I9NKm_3oz.png" alt="Redux Actions.drawio.png" class="image--center mx-auto" /></p>
<blockquote>
<p>Your app can change the state in the Redux store by dispatching actions. </p>
</blockquote>
<pre><code class="lang-javascript">dispatch(addTask(task))
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/ibjD5QfUTkw3wqQmv4/giphy.gif">https://media.giphy.com/media/ibjD5QfUTkw3wqQmv4/giphy.gif</a></div>
<p>An action only describes what needs to happen. It doesn't describe how we want the states to change. We need to use a reducer for this.</p>
<h2 id="heading-reducer">Reducer</h2>
<p>A reducer is a JS function that takes in <code>initialState</code> and <code>action</code> as input and returns an updated state object.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> initialState = {
  <span class="hljs-attr">tasks</span>: [],
  <span class="hljs-attr">taskTitle</span>: <span class="hljs-string">""</span>,
  <span class="hljs-attr">taskDescription</span>: <span class="hljs-string">""</span>
};

<span class="hljs-keyword">const</span> taskReducer = <span class="hljs-function">(<span class="hljs-params">state = initialState, action</span>) =&gt;</span> {
  <span class="hljs-keyword">switch</span> (action.type) {
    <span class="hljs-keyword">case</span> ADD_TASK:
      <span class="hljs-keyword">return</span> {
        ...state,
        <span class="hljs-attr">tasks</span>: [...state.tasks, action.payload],
        <span class="hljs-attr">taskTitle</span>: <span class="hljs-string">""</span>,
        <span class="hljs-attr">taskDescription</span>: <span class="hljs-string">""</span>
      };
    <span class="hljs-keyword">default</span>:
      <span class="hljs-keyword">return</span> state;
  }
};
</code></pre>
<p>When an action is dispatched, the relevant reducer will update the state according to the action.</p>
<p>When we create the Redux store, we feed all the reducers to the store. So, the reducers can update the state in the store which is what we want.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660980332333/PBNPf6Xsw.png" alt="Redux Cycle.drawio.png" class="image--center mx-auto" /></p>
<h1 id="heading-feeling-overwhelmed">Feeling Overwhelmed?</h1>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/4JVTF9zR9BicshFAb7/giphy.gif">https://media.giphy.com/media/4JVTF9zR9BicshFAb7/giphy.gif</a></div>
<p>I completely understand if you feel swamped, especially if you are only now becoming familiar with these ideas. Have no fear; I've been there. When we begin writing the code, you will have a better understanding of it.</p>
<h1 id="heading-adding-redux-to-your-react-app">Adding Redux to your React App</h1>
<p>Redux will be used to manage states in my simple to-do app, which will allow users to add tasks. I'm simply doing this as a demonstration; a basic app like this doesn't need redux.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660982494666/JW7dFlJY3.gif" alt="simple-todo-app.gif" class="image--center mx-auto" /></p>
<h2 id="heading-step-1-installing-required-libraries">Step 1 - Installing required libraries</h2>
<pre><code class="lang-javascript">npm i redux react-redux @reduxjs/toolkit
</code></pre>
<h2 id="heading-step-2-create-actions-action-types-and-action-creators">Step 2 - Create Actions, Action Types and Action Creators</h2>
<p><strong>taskActionTypes.js</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> ADD_TASK = <span class="hljs-string">"ADD_TASK"</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> UPDATE_TASK_TITLE = <span class="hljs-string">"UPDATE_TASK_TITLE"</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> UPDATE_TASK_DESCRIPTION = <span class="hljs-string">"UPDATE_TASK_DESCRIPTION"</span>;
</code></pre>
<p><strong>taskActions.js</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {ADD_TASK, UPDATE_TASK_DESCRIPTION, UPDATE_TASK_TITLE} <span class="hljs-keyword">from</span> <span class="hljs-string">"./taskActionTypes"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> addTask = <span class="hljs-function">(<span class="hljs-params">task</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">type</span>: ADD_TASK,
        <span class="hljs-attr">payload</span>: task,
    };
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> updateTaskTitle = <span class="hljs-function">(<span class="hljs-params">value</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">type</span>: UPDATE_TASK_TITLE,
        <span class="hljs-attr">payload</span>: value,
    };
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> updateTaskDescription = <span class="hljs-function">(<span class="hljs-params">value</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">type</span>: UPDATE_TASK_DESCRIPTION,
        <span class="hljs-attr">payload</span>: value,
    };
};
</code></pre>
<p>When we are passing values to action creators, the convention is to call that attribute "<strong>payload</strong>".</p>
<h2 id="heading-step-3-create-reducers">Step 3 - Create Reducer(s)</h2>
<p><strong>taskReducer.js</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {ADD_TASK, UPDATE_TASK_DESCRIPTION, UPDATE_TASK_TITLE} <span class="hljs-keyword">from</span> <span class="hljs-string">"./taskActionTypes"</span>;

<span class="hljs-keyword">const</span> initialState = {
    <span class="hljs-attr">tasks</span>: [],
    <span class="hljs-attr">taskTitle</span>: <span class="hljs-string">""</span>,
    <span class="hljs-attr">taskDescription</span>: <span class="hljs-string">""</span>
};

<span class="hljs-keyword">const</span> taskReducer = <span class="hljs-function">(<span class="hljs-params">state = initialState, action</span>) =&gt;</span> {
    <span class="hljs-keyword">switch</span> (action.type) {
        <span class="hljs-keyword">case</span> ADD_TASK:
            <span class="hljs-keyword">return</span> {
                ...state,
                <span class="hljs-attr">tasks</span>: [...state.tasks, action.payload],
                <span class="hljs-attr">taskTitle</span>: <span class="hljs-string">""</span>,
                <span class="hljs-attr">taskDescription</span>: <span class="hljs-string">""</span>
            };
        <span class="hljs-keyword">case</span> UPDATE_TASK_TITLE:
            <span class="hljs-keyword">return</span> {
                ...state,
                <span class="hljs-attr">taskTitle</span>: action.payload,
            }
        <span class="hljs-keyword">case</span> UPDATE_TASK_DESCRIPTION:
            <span class="hljs-keyword">return</span> {
                ...state,
                <span class="hljs-attr">taskDescription</span>: action.payload,
            }
        <span class="hljs-attr">default</span>:
            <span class="hljs-keyword">return</span> state;
    }
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> taskReducer;
</code></pre>
<p>In this case, we only need the taskReducer. But in a complex app, there will be multiple reducers to handle different states. In that case, the convention is to create a reducer called "<strong>rootReducer</strong>" by combining all the other reducers and feeding that reducer to the store.</p>
<p><strong>rootReducer.js</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {combineReducers} <span class="hljs-keyword">from</span> <span class="hljs-string">"redux"</span>;
<span class="hljs-keyword">import</span> taskReducer <span class="hljs-keyword">from</span> <span class="hljs-string">"./tasks/taskReducer"</span>;

<span class="hljs-keyword">const</span> rootReducer = combineReducers({<span class="hljs-attr">task</span>: taskReducer});

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> rootReducer
</code></pre>
<h2 id="heading-step-4-create-the-store">Step 4 - Create the Store</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { configureStore } <span class="hljs-keyword">from</span> <span class="hljs-string">"@reduxjs/toolkit"</span>;
<span class="hljs-keyword">import</span> rootReducer <span class="hljs-keyword">from</span> <span class="hljs-string">"./rootReducer"</span>;

<span class="hljs-keyword">const</span> store = configureStore({ <span class="hljs-attr">reducer</span>: rootReducer });

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> store;
</code></pre>
<h2 id="heading-step-5-wrap-the-root-component-with-provider">Step 5 - Wrap the Root Component with Provider</h2>
<p><strong>index.js</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">"react-dom/client"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./index.css"</span>;
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">"./App"</span>;
<span class="hljs-keyword">import</span> {Provider} <span class="hljs-keyword">from</span> <span class="hljs-string">"react-redux"</span>;
<span class="hljs-keyword">import</span> store <span class="hljs-keyword">from</span> <span class="hljs-string">"./redux/store"</span>;

<span class="hljs-keyword">const</span> root = ReactDOM.createRoot(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"root"</span>));
root.render(
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">React.StrictMode</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Provider</span> <span class="hljs-attr">store</span>=<span class="hljs-string">{store}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Provider</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">React.StrictMode</span>&gt;</span></span>
);
</code></pre>
<h2 id="heading-step-6-usedispatch-and-useselector">Step 6 - useDispatch() and useSelector()</h2>
<p>You can use useSelector() to access the states in the Redux store.</p>
<p>You can use useDispatch() to access the dispatch method which helps you to dispatch actions</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> {useDispatch, useSelector} <span class="hljs-keyword">from</span> <span class="hljs-string">"react-redux"</span>;
<span class="hljs-keyword">import</span> {addTask, updateTaskDescription, updateTaskTitle} <span class="hljs-keyword">from</span> <span class="hljs-string">"../redux/tasks/taskActions"</span>;

<span class="hljs-keyword">const</span> styles = {
    <span class="hljs-attr">taskContainer</span>: {
        <span class="hljs-attr">display</span>: <span class="hljs-string">"flex"</span>,
        <span class="hljs-attr">flexDirection</span>: <span class="hljs-string">"column"</span>,
        <span class="hljs-attr">width</span>: <span class="hljs-string">"350px"</span>
    },
    <span class="hljs-attr">mainContainer</span>: {
        <span class="hljs-attr">textAlign</span>: <span class="hljs-string">'-webkit-center'</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">AddTasks</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> dispatch = useDispatch();
    <span class="hljs-keyword">const</span> taskTitle = useSelector(<span class="hljs-function"><span class="hljs-params">state</span> =&gt;</span> state.task.taskTitle)
    <span class="hljs-keyword">const</span> taskDescription = useSelector(<span class="hljs-function"><span class="hljs-params">state</span> =&gt;</span> state.task.taskDescription)

    <span class="hljs-keyword">const</span> onAddTask = <span class="hljs-function">() =&gt;</span> {
        <span class="hljs-keyword">const</span> task = {
            <span class="hljs-attr">title</span>: taskTitle,
            <span class="hljs-attr">description</span>: taskDescription,
        }
        dispatch(addTask(task))
    };
    <span class="hljs-keyword">const</span> onTaskTitleChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> dispatch(updateTaskTitle(e.target.value))
    <span class="hljs-keyword">const</span> onTaskDescriptionChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> dispatch(updateTaskDescription(e.target.value))

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.mainContainer}</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles.taskContainer}</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Task Title"</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{onTaskTitleChange}</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{taskTitle}</span> /&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Task Description"</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{onTaskDescriptionChange}</span>
                       <span class="hljs-attr">value</span>=<span class="hljs-string">{taskDescription}</span> /&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{onAddTask}</span>&gt;</span>Add Task<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> AddTasks;
</code></pre>
<p>That's about it. We successfully added Redux to a React app. </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/OtSERKyJriAzUZoF53/giphy.gif">https://media.giphy.com/media/OtSERKyJriAzUZoF53/giphy.gif</a></div>
<p>If you want to look into the code and try in out for yourself, here is the Code Sandbox version.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codesandbox.io/embed/divine-platform-43jj6l?fontsize=14&amp;hidenavigation=1&amp;theme=dark">https://codesandbox.io/embed/divine-platform-43jj6l?fontsize=14&amp;hidenavigation=1&amp;theme=dark</a></div>
<h1 id="heading-conclusion">Conclusion</h1>
<p>At first glance, adding Redux to your React app could appear difficult. But it gets a lot simpler when we take each concept in turn and develop the logic on our own.</p>
<p>I am still trying to learn these concepts on my own. Please feel free to bring up any gaps in my reasoning and the problems you encounter.</p>
<p>Thank you for reading my article. If you learned something new, please make sure to drop a like and share the article among your fellow developers 🥳</p>
]]></content:encoded></item><item><title><![CDATA[Make Errors User-Friendly with React Error Boundaries]]></title><description><![CDATA[What are Error Boundaries ?
React Error Boundaries are used to show a user-friendly UI to users when unexpected JavaScript errors occur.
A JavaScript error in a part of the UI usually renders a white screen and crashes the entire app. React Version 1...]]></description><link>https://blog.thisurathenuka.dev/make-errors-user-friendly-with-react-error-boundaries</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/make-errors-user-friendly-with-react-error-boundaries</guid><category><![CDATA[React]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[error handling]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 13 Aug 2022 16:03:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660406516166/z5sY-_Hqy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-are-error-boundaries">What are Error Boundaries ?</h1>
<p>React Error Boundaries are used to show a user-friendly UI to users when unexpected JavaScript errors occur.</p>
<p>A JavaScript error in a part of the UI usually renders a white screen and crashes the entire app. React Version 16 introduced a solution to this issue with the new “Error Boundary” concept.</p>
<h1 id="heading-how-can-i-implement-error-boundaries">How can I implement Error Boundaries ?</h1>
<p>You can implement React Error Boundaries in your React app in 2 simple steps</p>
<ol>
<li>Create an error boundary component</li>
<li>Wrap error-prone component with error boundary component</li>
</ol>
<h2 id="heading-creating-error-boundary-component">Creating Error Boundary Component</h2>
<blockquote>
<p>A class component becomes an error boundary if it defines either (or both) of the lifecycle methods <code>static getDerivedStateFromError()</code> or <code>componentDidCatch()</code>. Use <code>static getDerivedStateFromError()</code> to render a fallback UI after an error has been thrown. Use <code>componentDidCatch()</code> to log error information. (https://reactjs.org/docs/error-boundaries.html)</p>
</blockquote>
<p>Here is the example error boundary component provided in the React documentation.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ErrorBoundary</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
    <span class="hljs-keyword">constructor</span>(props) {
      <span class="hljs-built_in">super</span>(props);
      <span class="hljs-built_in">this</span>.state = { <span class="hljs-attr">error</span>: <span class="hljs-literal">null</span>, <span class="hljs-attr">errorInfo</span>: <span class="hljs-literal">null</span> };
    }

    componentDidCatch(error, errorInfo) {
      <span class="hljs-comment">// Catch errors in any components below and re-render with error message</span>
      <span class="hljs-built_in">this</span>.setState({
        <span class="hljs-attr">error</span>: error,
        <span class="hljs-attr">errorInfo</span>: errorInfo
      })
      <span class="hljs-comment">// You can also log error messages to an error reporting service here</span>
    }

    render() {
      <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.state.errorInfo) {
        <span class="hljs-comment">// Error path</span>
        <span class="hljs-keyword">return</span> (
          <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Something went wrong.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">details</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">whiteSpace:</span> '<span class="hljs-attr">pre-wrap</span>' }}&gt;</span>
              {this.state.error &amp;&amp; this.state.error.toString()}
              <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
              {this.state.errorInfo.componentStack}
            <span class="hljs-tag">&lt;/<span class="hljs-name">details</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        );
      }
      <span class="hljs-comment">// Normally, just render children</span>
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.props.children;
    }  
  }

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> ErrorBoundary;
</code></pre>
<p>You can create your own error boundary with a fancier UI according to your use case.</p>
<h2 id="heading-wrapping-with-error-boundary">Wrapping with Error Boundary</h2>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/GA1s4aZhfe5f2N3fFb/giphy.gif">https://media.giphy.com/media/GA1s4aZhfe5f2N3fFb/giphy.gif</a></div>
<p>There are two ways you could wrap components with the error boundary</p>
<ol>
<li>You can wrap the top-level component</li>
<li>You can wrap individual components</li>
</ol>
<h3 id="heading-wrapping-top-level-component">Wrapping Top-Level Component</h3>
<pre><code class="lang-javascript">&lt;ErrorBoundary&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span>/&gt;</span></span>
&lt;/ErrorBoundary&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660404384998/gfIIneZPt.gif" alt="error-boundaries-for-root.gif" /></p>
<h3 id="heading-wrapping-individual-components">Wrapping Individual Components</h3>
<p>This approach would be ideal if your app has multiple different isolated sections.</p>
<pre><code class="lang-javascript">&lt;ErrorBoundary&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">BankingController</span>/&gt;</span></span>
&lt;/ErrorBoundary&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ErrorBoundary</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ProfileController</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ErrorBoundary</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ErrorBoundary</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">PolicyController</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ErrorBoundary</span>&gt;</span></span>
</code></pre>
<p>An error occurred in BankingController would not stop user from using the PolicyController or ProfileController.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660404527090/rbKn43gAg.gif" alt="error-boundaries-for-individual.gif" /></p>
<h1 id="heading-so-is-my-react-app-white-screen-free-now">So, Is my React app “white screen”-free now?</h1>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/l3q2K5jinAlChoCLS/giphy.gif">https://media.giphy.com/media/l3q2K5jinAlChoCLS/giphy.gif</a></div>
<p>Well, React error boundaries can catch all errors except for the following :</p>
<ol>
<li>Event Handlers</li>
<li>Asynchronous code</li>
<li>Server Side Rendering</li>
<li>Errors thrown in the error boundary itself</li>
</ol>
<p>But you can always make use of regular JavaScript try/catch blocks whenever needed.</p>
<blockquote>
<p>As of React 16, errors that were not caught by any error boundary will result in unmounting of the whole React component tree</p>
</blockquote>
<h1 id="heading-conclusion">Conclusion</h1>
<p>React error boundaries provide a way for developers to make our apps more user-friendly. In my opinion, every React app should make use of React error boundaries and it makes a drastic difference in the user experience.</p>
<p>Thank you for taking the time to read my article. Hope you enjoyed it. If you learned something new, make sure to drop a like and share the article with your fellow developers. </p>
]]></content:encoded></item><item><title><![CDATA[How to Write Our Own Custom Hooks in React]]></title><description><![CDATA[To make life simpler for developers, React has introduced a wide variety of hooks. In addition, React allows us to build our own custom hooks.
Today, I will explain how we can create and use React custom hooks.
What are Custom Hooks in React?
React c...]]></description><link>https://blog.thisurathenuka.dev/how-to-write-our-own-custom-hooks-in-react</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/how-to-write-our-own-custom-hooks-in-react</guid><category><![CDATA[React]]></category><category><![CDATA[ReactHooks]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sun, 26 Jun 2022 11:13:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1656240566405/Hqn04p6FY.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>To make life simpler for developers, React has introduced a wide variety of hooks. In addition, React allows us to build our own custom hooks.</p>
<p>Today, I will explain how we can create and use React custom hooks.</p>
<h1 id="heading-what-are-custom-hooks-in-react">What are Custom Hooks in React?</h1>
<p>React custom hooks are a way to extract component logic into reusable functions. There is one convention you should know about before writing our own React hooks</p>
<h2 id="heading-use-in-front-of-the-custom-hook">"use" in front of the custom hook</h2>
<p>React advises us to only use React hooks inside React functional components or custom hooks. React advises us not to use React hooks inside regular JS functions. The thought process behind this is that if we use React hooks inside normal JS functions, there is a chance for them to get "hidden" inside the call stack. Especially in a large codebase, it would be impossible to go through each and every function to see where React hooks have been used.</p>
<p>The thought process is the same in this case as well. It would be simpler for us to determine where React hooks have been used if we prefixed our custom hook names with "use".</p>
<p>So, the name of your custom hook should look like this</p>
<pre><code class="lang-plaintext">useMyCustomHook()
useOnlineStatus()
useCommentFilter()
</code></pre>
<h1 id="heading-how-to-write-react-custom-hooks">How to write React Custom Hooks?</h1>
<p>I've created a simple React hook to check if a given player is retired or not.</p>
<p><strong>useRetiredStatus.js</strong></p>
<pre><code class="lang-plaintext">import {useEffect, useState} from "react";

const useRetiredStatus = (player) =&gt; {

    const [isRetired, setIsRetired] = useState(null);

    useEffect(() =&gt; {
        //Assumption: The age of retirement for cricket is 40 yrs
        player?.age &gt; 40 ? setIsRetired(true) : setIsRetired(false)
    })

    return isRetired;
}

export default useRetiredStatus;
</code></pre>
<p><strong>App.js</strong></p>
<pre><code class="lang-plaintext">import React, {useEffect, useState} from 'react';
import useRetiredStatus from "./useRetiredStatus";

const players = [
    {name: "Kumar Sangakkara", age: 44},
    {name: "Angelo Mathews", age: 35},
    {name: "Rohit Sharma", age: 35},
    {name: "Mahela Jayawardene", age: 45},
    {name: "David Miller ", age: 33},
]

function App() {

    const [player, setPlayer] = useState(players[2]);
    const retiredStatus = useRetiredStatus(player);

    return (
        &lt;&gt;
            {`Dear Cricket Fans, ${player.name} is ${retiredStatus ? 'retired' : 'still playing the game'}`}
        &lt;/&gt;
    );
}

export default App;
</code></pre>
<p><strong>Output</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656237172992/FSXe2bh_-.png" alt="image.png" /></p>
<p>With React Custom Hooks, there are no limitations. We can change input and output variables into anything we want just like in a regular function. With this knowledge, you will be able to create custom hooks for all the unique requirements in your projects.</p>
<h1 id="heading-cant-i-just-use-a-js-function-instead-of-creating-a-custom-hook">Can't I just use a JS function, instead of creating a custom hook?</h1>
<p>You can use a JS function if your code does not make use of React hooks.</p>
<p>If the code contains React hooks, you should create a custom hook so that your code aligns with <a target="_blank" href="https://reactjs.org/docs/hooks-rules.html">React's rules of hooks</a></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Learning how to make use of React custom hooks will make your code look more cleaner and more readable. I hope you will be able to implement React custom hooks in your next project.</p>
<p>Thank you for reading the article. Hope you learned something valuable today. Until next time, take care guys.</p>
]]></content:encoded></item><item><title><![CDATA[Promises - JavaScript Concepts Simplified]]></title><description><![CDATA[What is a Promise?
By definition, a promise is a declaration that one will do something or that a particular thing will happen. In the programming world, a promise is an object that represents the eventual completion (or failure) of an asynchronous o...]]></description><link>https://blog.thisurathenuka.dev/promises-javascript-concepts-simplified</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/promises-javascript-concepts-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[promises]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 12 Feb 2022 14:57:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1644677803815/leyb6l7I_.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-is-a-promise">What is a Promise?</h1>
<p>By definition, a promise is a declaration that one will do something or that a particular thing will happen. In the programming world, a promise is an object that represents the eventual completion (or failure) of an asynchronous operation.</p>
<h1 id="heading-states">States</h1>
<p>A promise can have the following states.</p>
<ol>
<li>Pending (Initial State, neither <code>fulfilled</code> nor ``` rejected</li>
</ol>
<pre><code class="lang-plaintext">2. Fulfilled (The operation was a success)
3. Rejected (The operation was a failure)

A pending promise can either be fulfilled or rejected. We can attach handler methods to handle the events of promises getting ```
fulfilled
``` and ```
rejected
```. We can use the ```
then
``` method in promises to attach these handlers.
</code></pre>
<p>promise.then(handleSuccess, handleRejection)</p>
<pre><code class="lang-plaintext">
We have attached two handler methods to the above promise. Now, if the promise gets fulfilled, ```
handleSuccess
``` will be called and if it gets rejected, the ```
handleRejection
``` method will be called.

When a promise is not in the ```
pending
``` state, we say the promise is ```
settled
```. Please keep in mind that being settled is merely a linguistic convenience, not a state.

# Methods

In addition, promise objects have multiple methods that can be really useful when handling promises.

## 1. Promise.all()

Input - An iterable of promises

Output - A single promise that resolves into an array of the results of the input promises

This method is useful when you have more than one promise and you want to do something only when all the operations are completed successfully. ```
Promise.all()
``` will reject immediately upon any of the input promises being rejected. For example, if you want to make multiple API calls and the code relies on all of them to be successful, you can use Promise.all()
</code></pre>
<p>const firstPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 300, "First Promise"); });</p>
<p>const secondPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 100, "Second Promise"); });</p>
<p>const thirdPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 1000, "Third Promise"); });</p>
<p>const rejectedPromise = Promise.reject("EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED");</p>
<p>//Promise.all() method Promise.all([firstPromise, secondPromise, thirdPromise]) .then((results) =&gt; { console.log("All the promises were fulfilled here - ", results); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<p>//Promise.all() method with a rejected promise Promise.all([firstPromise, rejectedPromise, thirdPromise]) .then((results) =&gt; { console.log("All the promises were fulfilled"); console.log("Response from all method - ", results); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<pre><code class="lang-plaintext">
Output
</code></pre>
<p>Error: EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED All the promises were fulfilled here - [ 'First Promise', 'Second Promise', 'Third Promise' ]</p>
<pre><code class="lang-plaintext">
## 2. Promise.allSettled()

Input - An iterable of promises

Output - A single promise that resolves into an array of the results of the input promises

We can use this method when the tasks are dependent on each other and you want to know all the results of all the promises regardless of the result of each promise.
</code></pre>
<p>//Promise.allSettled() method with a rejected promise Promise.allSettled([firstPromise, rejectedPromise, thirdPromise]) .then((results) =&gt; { console.log("I don't care if all the results are fulfilled or not"); console.log("Response from allSettled method - ", results); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<pre><code class="lang-plaintext">
You can clearly see the difference between the ```
all
``` and ```
allSettled
``` methods. The ```
all
``` method wants all the promises to be fulfilled while ```
allSettled
``` method only wants the promises to be ```
settled
``` (regardless of ```
fulfilled
``` or not
)

Output
</code></pre>
<p>I don't care if all the results are fulfilled or not Response from allSettled method - [ { status: 'fulfilled', value: 'First Promise' }, { status: 'rejected', reason: 'EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED' }, { status: 'fulfilled', value: 'Third Promise' } ]</p>
<pre><code class="lang-plaintext">
## 3. Promise.any()

Input - An iterable of promises

Output - A single promise that resolves as soon as any of the promises in the iterable fulfils, with the value of the fulfilled promise

If none of the promises gets fulfilled, a ```
AggregateError 
```will reject the promise
</code></pre>
<p>const firstPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 300, "First Promise"); });</p>
<p>const secondPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 100, "Second Promise"); });</p>
<p>const thirdPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 1000, "Third Promise"); });</p>
<p>const rejectedPromise = Promise.reject( "EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED" );</p>
<p>//Promise.any() Method Promise.any([firstPromise, secondPromise]) .then((fasterPromise) =&gt; { console.log("Response from any method with no rejections - ", fasterPromise); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<p>//Promise.any() Method with rejections Promise.any([rejectedPromise, rejectedPromise]) .then((fasterPromise) =&gt; { console.log("Response from any method with rejections - ", fasterPromise); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<p>//Promise.any() Method Promise.any([firstPromise, secondPromise]).then((fasterPromise) =&gt; { console.log("Response from any method - ", fasterPromise); });</p>
<pre><code class="lang-plaintext">Output
</code></pre>
<p>Error: [AggregateError: All promises were rejected] Response from any method with no rejections - Second Promise</p>
<pre><code class="lang-plaintext">
## 4. Promise.race()

Input - An iterable of promises

Output - A promise that fulfils or rejects as soon as one of the promises in an iterable fulfils or rejects, with the value or reason from that promise
</code></pre>
<p>const firstPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 300, "First Promise"); });</p>
<p>const secondPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 100, "Second Promise"); });</p>
<p>const thirdPromise = new Promise((resolve, reject) =&gt; { setTimeout(resolve, 1000, "Third Promise"); });</p>
<p>const rejectedPromise = Promise.reject( "EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED" );</p>
<p>//Promise.race() Method Promise.race([firstPromise, secondPromise]) .then((fasterPromise) =&gt; { console.log( "Response from race method with no rejections - ", fasterPromise ); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<p>//Promise.race() Method with rejections Promise.race([secondPromise, rejectedPromise]) .then((fasterPromise) =&gt; { console.log("Response from race method with rejections - ", fasterPromise); }) .catch((error) =&gt; { console.error("Error: ", error); });</p>
<pre><code class="lang-plaintext">
As the name of the method suggests, we have a race here. It does not matter whether the promises are fulfilled or rejected. The ```
race
``` method returns the fastest settled promise.

Output
</code></pre>
<p>Error: EVERYBODY STAY CALM. STAY F***ING CALM. I WAS REJECTED Response from race method with no rejections - Second Promise</p>
<pre><code class="lang-plaintext">
## 5. Promise.reject() and Promise.resolve()

You are already familiar with the ```
reject
``` method since I’ve used it in earlier examples. Basically, we use the ```
reject
``` method to reject a promise.

In addition, we have the ```
resolve
``` method which returns a promise that is resolved with the given value or the promise passed as value, if the value was a promise object. Resolved is not to be confused with ```
fulfilled
```. Please read [this StackOverflow answer](https://stackoverflow.com/questions/35398365/js-promises-fulfill-vs-resolve) to learn more about it.

# Fates

Promises also have two mutually exclusive fates, resolved and unresolved.

1. If we try to resolve or reject a promise and it has no effect, we say the promise is resolved.
2. If we try to resolve or reject a promise and it has an effect, we say the promise is unresolved.

# Conclusion

To sum things up, we use promises to handle asynchronous operations in JavaScript. Especially, when there are multiple asynchronous operations running, it would be a nightmare to handle them if you don't know about promises.

I hope you learned something valuable from Today's article. If you liked it, drop a like and follow me so that you don't miss the upcoming articles. And as always, stay safe guys 😷
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Higher-Order Functions - JavaScript Concepts Simplified]]></title><description><![CDATA[Hello guys, I'm back with another article in my JavaScript Concepts Simplified series. Today, I'm going to go through the concept of Higher-Order Functions.
This is not necessarily specific to JavaScript per se. But it is an essential concept you mus...]]></description><link>https://blog.thisurathenuka.dev/higher-order-functions-javascript-concepts-simplified</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/higher-order-functions-javascript-concepts-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Thu, 23 Sep 2021 14:00:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1632405116197/DDGfxADs-.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello guys, I'm back with another article in my <strong>JavaScript Concepts Simplified</strong> series. Today, I'm going to go through the concept of Higher-Order Functions.</p>
<p>This is not necessarily specific to JavaScript per se. But it is an essential concept you must learn when going forward with JavaScript. If you read my article regarding closures, you do already have some experience with higher-order functions even if you do not have an idea.</p>
<p>The term, <strong>Higher-Order Functions</strong> aka <strong>HOF</strong>s, is said to be <a target="_blank" href="https://softwareengineering.stackexchange.com/questions/186035/who-first-coined-the-term-higher-order-function-and-or-first-class-citizen">coined way back in 1891</a>.</p>
<h1 id="heading-useful-terminology">Useful Terminology</h1>
<p>Before learning Higher-Order functions, let's quickly check out few other concepts that would aid you in understanding higher-order functions better.</p>
<h2 id="heading-functional-programming">Functional Programming</h2>
<blockquote>
<p>Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and the application state flows through pure functions. Contrast with object-oriented programming, where application state is usually shared and colocated with methods in objects.</p>
</blockquote>
<p><a target="_blank" href="https://medium.com/javascript-scene/master-the-javascript-interview-what-is-functional-programming-7f218c68b3a0">Source - Medium</a></p>
<h2 id="heading-first-class-functions">First-Class Functions</h2>
<p>In a programming language where functions are treated as variables, it is said to have <strong>First-Class functions</strong>. In such a language like JS, a function can be passed as an argument to other functions, can be assigned as a value to a variable and can be returned by another function</p>
<h1 id="heading-what-is-a-higher-order-function">What is a Higher-Order Function?</h1>
<p>A Higher-Order Function is a function that does at least one of the following things.</p>
<ol>
<li><p>Takes one or more functions as arguments</p>
</li>
<li><p>Returns a function as a result</p>
</li>
</ol>
<p>All the functions that are not higher-order functions are called <strong>first-order functions</strong>.</p>
<h1 id="heading-usage">Usage</h1>
<p>JavaScript has a list of inbuilt HOFs as well as we can write our own HOFs.</p>
<h2 id="heading-inbuilt-higher-order-functions">Inbuilt Higher-Order Functions</h2>
<h3 id="heading-array-filter-method">Array filter method</h3>
<pre><code class="lang-plaintext">const numbers = [1, 2, 3, 4, 5, 6, 7]
const smallerThanFive = x =&gt; x &lt; 5
console.log(numbers.filter(smallerThanFive)) // [1, 2, 3, 4]
</code></pre>
<p>As you can see, we are <em>passing a function</em> called <strong>smallerThanFive</strong> to the filter method as the callback function. Read more on the filter method <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">here</a>.</p>
<h3 id="heading-array-find-method">Array find method</h3>
<pre><code class="lang-plaintext">const innings = [
    {player: "Sanga", score: 59},
    {player: "Mahela", score: 70},
    {player: "Angie", score: 85}
];
const higherThanSeventyFive = inning =&gt; inning.score &gt; 75
console.log(innings.find(higherThanSeventyFive)) //{ player: 'Angie', score: 85 }
</code></pre>
<p>As you can see, we are <em>passing a function</em> called <strong>higherThanSeventyFive</strong> to the find method as the callback function. Read more on the find method <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find">here</a>.</p>
<h3 id="heading-array-map-method">Array map method</h3>
<pre><code class="lang-plaintext">const numbers = [1, 2, 3, 4]
const multiplyByTwo = x =&gt; x * 2
console.log(numbers.map(multiplyByTwo)) // [2, 4, 6, 8]
</code></pre>
<p>As you can see, we are <em>passing a function</em> called <strong>multiplyByTwo</strong> to the map method as the callback function. Read more on the map method <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map">here</a>.</p>
<p>The list goes on and on. I'd like to recommend you to check out the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">MDN Docs articles on Array methods</a> to learn more.</p>
<h2 id="heading-custom-higher-order-functions">Custom Higher-Order Functions</h2>
<p>Since all the above examples were about passing functions as parameters, let's make our own higher-order function return a function.</p>
<pre><code class="lang-plaintext">const multiply = (firstValue) =&gt; (secondValue) =&gt; firstValue * secondValue
</code></pre>
<p>Let me write this without the arrow function syntax to make things a bit clearer for you.</p>
<pre><code class="lang-plaintext">function multiply (firstValue) {
  return function (secondValue){
    return firstValue * secondValue;
  }
}
</code></pre>
<p>The <strong>multiply</strong> function gets the <strong>firstValue</strong> as an argument and returns a function that asks for the <strong>secondValue</strong> as an argument. Here is how you call this function.</p>
<pre><code class="lang-plaintext">multiply(10)(20) //Returns 200
</code></pre>
<p>Some of you might be thinking, "<em>We can just write this in a single function and pass both values into that. Why did you use a higher-order function for this?</em>". Yes, you are right. There is no need for writing a higher-order function to multiply two values.</p>
<p>But, if you want to make the inner functions not accessible to the outside, you can write a higher-order function. And learning to write higher-order functions would save you a lot of time.</p>
<p>I know this could be hard to grasp, especially if you are new to functional programming. I believe you understand what is happening in the above function. But some of you might not still understand the thinking process behind writing a higher-order function like this.</p>
<p>Let me take you through the thinking process so that you can attempt writing your own higher-order function.</p>
<h2 id="heading-explaining-the-thought-process">Explaining The Thought Process</h2>
<pre><code class="lang-plaintext">function multiply (firstValue) {
  //Do some stuff with firstValue
}

multiply(10)
</code></pre>
<p>Here you have a normal function that takes in an argument called <strong>firstValue</strong>. And then you realize that you have to write another function, but you don't want to make it accessible from the outside. So, what are your options?</p>
<pre><code class="lang-plaintext">function multiply (firstValue) {
  //Do some stuff with firstValue
  return function (secondValue) {
    //Do some stuff with firstValue and secondValue
  }
}

multiply(10)(20)
</code></pre>
<p>You can write it as a nested function. But then, there is no way for you to pass arguments from outside (You can pass the value to the outer function and then pass it to the inner function. But that is not a good coding practice). What you can do is to return the inner function and take in an argument from the inner function. Likewise, you can just keep writing functions inside functions as much as you need.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>To sum things up, higher-order functions are just like regular functions in JavaScript. The only difference is that while the regular functions take in variables and return variables, Higher-Order functions take in functions and return functions.</p>
<p>I hope you learned something valuable from Today's article. If you liked it, drop a like and follow me so that you don't miss the upcoming articles. And as always, stay safe guys 😷</p>
]]></content:encoded></item><item><title><![CDATA[Closures - JavaScript Concepts Simplified]]></title><description><![CDATA[Hello guys, Today we are going to go over the concept of closure in JavaScript.
Background Terms
IIFEs aka Immediately Invoked Function Expressions are JavaScript functions that run as soon as they are defined. I am already writing a detailed article...]]></description><link>https://blog.thisurathenuka.dev/closures-javascript-concepts-simplified</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/closures-javascript-concepts-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[closure]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Mon, 20 Sep 2021 11:28:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1632136974793/zh-wK8Egl.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello guys, Today we are going to go over the concept of <strong>closure</strong> in JavaScript.</p>
<h1 id="heading-background-terms">Background Terms</h1>
<p><strong>IIFE</strong>s aka Immediately Invoked Function Expressions are JavaScript functions that run as soon as they are defined. I am already writing a detailed article regarding IIFEs. So until then, if you do not know about IIFEs, just think of it as an anonymous function that runs automatically and here is the default syntax for it.</p>
<pre><code class="lang-plaintext">(function () {
  //Write your code here
})()
</code></pre>
<p><strong>Lexical scope</strong> is the concept of <strong>a variable defined outside a function</strong> being <strong>accessible inside another function</strong> defined after the variable declaration</p>
<h1 id="heading-what-is-a-closure">What is a Closure?</h1>
<blockquote>
<p>A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time</p>
</blockquote>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">Source - MDN Docs</a></p>
<p>Let me simplify. Think you have an IIFE that has a variable called <strong>total</strong>.</p>
<pre><code class="lang-plaintext">(function () {
  let total = 0
})();
</code></pre>
<p>Usually, since the <strong>total</strong> variable is defined inside the IIFE as a local variable, we can only use the <strong>total</strong> variable inside the IIFE.</p>
<p>But there is one way around it. If you define another function inside the IIFE, then that function also can access the variables of the parent function (IIFE) and hence can access the <strong>total</strong>. Here is how that would look like.</p>
<pre><code class="lang-plaintext">(function () {
  let total = 0
  function print() {
    console.log("Here is the total : ", total)
  }
  print();
})();
</code></pre>
<p>This prints <strong>total</strong>'s current value (0) on the console.</p>
<p>So, now you would say, "Right, but still the <strong>total</strong> variable is only accessible from inside the IIFE". Yes, you are absolutely right. So, let's just return the function.</p>
<p>You can think of functions in JavaScript as another variable type. We can just return the function and assign it into a variable. And since we are assigning the function reference to a variable, we don't even have to have a name for the inner function. Cool, right?</p>
<pre><code class="lang-plaintext">const addition = (function () {
  let total = 0
  return function (){
    total += 1
    console.log("The total is : ", total)
  }
})();

addition()
addition()
</code></pre>
<p>Here is the console output</p>
<pre><code class="lang-plaintext">The total is :  1
The total is :  2
</code></pre>
<p>Please note that <strong>the outer function doesn't have to be an IIFE</strong>. You can use the same concept with normal functions as well like in the following code snippet. I'm just using IIFEs to make the code cleaner.</p>
<pre><code class="lang-plaintext">//Using Normal Functions
function addition() {
  let total = 0;
  return function () {
    total += 1;
    console.log("The total is : ", total);
  };
}

//This returns the same console output as before
let returningFunction = addition()
returningFunction()
returningFunction()
</code></pre>
<p>You can just call this function as much as you want now. You are updating the value of a local variable from outside the function. This is the concept of <strong>closure</strong> in JavaScript.</p>
<p>If you want, we can take this a step further by <strong>returning a set of functions</strong> like this.</p>
<pre><code class="lang-plaintext">const manipulate = (function () {
  let total = 0
  return {
    increment : function () {
      total += 1
      console.log("The total is : ", total)
    },
    decrement: function () {
      total -= 1
      console.log("The total is : ", total)
    }
  }
})();

manipulate.increment()
manipulate.increment()
manipulate.decrement()
</code></pre>
<p>Here is the console output</p>
<pre><code class="lang-plaintext">The total is :  1
The total is :  2
The total is :  1
</code></pre>
<h1 id="heading-multiple-nested-functions">Multiple Nested Functions</h1>
<p>Take a look at this example from the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">MDN Docs</a></p>
<pre><code class="lang-plaintext">// global scope
var e = 10;
function sum(a){
  return function(b){
    return function(c){
      // outer functions scope
      return function(d){
        // local scope
        return a + b + c + d + e;
      }
    }
  }
}

console.log(sum(1)(2)(3)(4)); // log 20
</code></pre>
<p>As you can see we can just keep writing anonymous functions inside functions and use all the passed values. This also can be done using named functions as well. But you have to write few more lines when calling the functions.</p>
<pre><code class="lang-plaintext">// global scope
var e = 10;
function sum(a){
  return function sum2(b){
    return function sum3(c){
      // outer functions scope
      return function sum4(d){
        // local scope
        return a + b + c + d + e;
      }
    }
  }
}

var sum2 = sum(1);
var sum3 = sum2(2);
var sum4 = sum3(3);
var result = sum4(4);
console.log(result) //log 20
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Well, that is pretty much all you need to know to get started with JavaScript closures. Try to think of where you can add closure in your codebases. We will only get better if we start practising these concepts on a daily basis.</p>
<p>If you want to learn more in-depth stuff regarding closures like performance considerations, you should check out <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">the MDN Docs article</a>.</p>
<p>Thank you for reading my article. I hope you learned something valuable today. If you did, don't forget to follow my blog and share the article with your friends. And more importantly, stay safe 😷</p>
]]></content:encoded></item><item><title><![CDATA[Event Bubbling - JavaScript Concepts Simplified]]></title><description><![CDATA[Hello guys, welcome to another article in the JavaScript Concepts Simplified article series. Today, we'll be looking into Event Bubbling in JavaScript.
I'm just going to go through some of the basic things you need to know before going into the main ...]]></description><link>https://blog.thisurathenuka.dev/event-bubbling-javascript-concepts-simplified</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/event-bubbling-javascript-concepts-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[events]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 18 Sep 2021 17:26:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1631985186445/4cPnbnuIoQ.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello guys, welcome to another article in the JavaScript Concepts Simplified article series. Today, we'll be looking into Event Bubbling in JavaScript.</p>
<p>I'm just going to go through some of the basic things you need to know before going into the main event.</p>
<h2 id="heading-background-knowledge">Background Knowledge</h2>
<p>An <strong>event</strong> is an action or an occurrence that happens in your system. The simplest example would be the user clicking on a button.</p>
<p>For each event that is fired, we can write an <strong>event handler</strong> (A JavaScript function to handle the event) to do what we want to do. For example, we can write an event handler function to print something on the screen once the user clicks on the button.</p>
<p>We also have <strong>event listeners</strong> in JavaScript. Event listeners listen to the events happening. So, if we want to print something on the screen once the user clicks on the button, we need to first create an event listener to listen for the click event of the button.</p>
<p>When we are loading HTML pages in browsers, the browser creates a tree-like structure for each page called the <strong>DOM</strong>. For example, if you have a button inside your <em>body </em> tag, the path to the button element would be <strong>html</strong> -&gt; <strong>body</strong> -&gt; <strong>button</strong>.</p>
<h2 id="heading-three-phases-of-event-handling">Three Phases of Event Handling</h2>
<p>When it comes to handling events, modern browsers have three phases.</p>
<ol>
<li>Capturing Phase</li>
<li>Target Phase</li>
<li>Bubbling Phase</li>
</ol>
<h3 id="heading-the-capturing-phase">The Capturing Phase</h3>
<blockquote>
<p>The browser checks to see if the element's outer-most ancestor has an onclick event handler registered on it for the capturing phase, and runs it if so.</p>
</blockquote>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events">Source - MDN Docs</a> </p>
<h3 id="heading-the-target-phase">The Target Phase</h3>
<blockquote>
<p>The browser checks to see if the target property has an event handler for the click event registered on it, and runs it if so.</p>
<p> Then, if <strong>bubbles</strong> is true, it propagates the event to the direct parent of the selected element, then the next one, and so on. Otherwise, if <strong>bubbles</strong> is false, it doesn’t propagate the event to any ancestors of the target.</p>
</blockquote>
<p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events">Source - MDN Docs</a> </p>
<h3 id="heading-the-bubbling-phase">The Bubbling Phase</h3>
<blockquote>
<p>The browser checks to see if the direct parent of the element selected has an onclick event handler registered on it for the bubbling phase, and runs it if so.</p>
</blockquote>
<p> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events">Source - MDN Docs</a></p>
<h2 id="heading-wait-what">Wait, What?</h2>
<p>It is hard to grasp the issue by reading the above lines. Let me simplify. Here is the issue we are facing. </p>
<p>Think you have created a UI with two <strong>div</strong> blocks (Block A and Block B). Block B is placed inside Block A. And you have created event handlers for the click event of both <strong>div</strong> tags.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1631984146622/O4Tj89WAq.png" alt="image.png" /></p>
<p>Now when you click on <strong>Block B</strong>, before calling B's event handler, the browser calls A's event handler function. Obviously, this is not what we expected. When we click on B, only the event handler of B should be called.</p>
<h2 id="heading-how-do-we-fix-this">How do we fix this?</h2>
<p>Luckily, we do have a solution for this. In the <strong>event</strong> object, we have a function called <strong>stopPropogation</strong>. You can call this function at the start of the event handler function of B. You will see that only the event handler function of B is getting executed this time.</p>
<h2 id="heading-when-is-event-bubbling-useful">When is Event Bubbling Useful?</h2>
<p>There could be some use cases where this can be useful. For example, when you have a list of items and you want to do something for all of the items, you will usually have to add event listeners for all the items.</p>
<p>But since you now know the concept of event bubbling, you can just write and assign the event handler for the parent node and see the magic happen.</p>
<p>This concept is called <strong>event delegation</strong>. You can read more on that in  <a target="_blank" href="https://davidwalsh.name/event-delegate">this article</a>.</p>
<p>Thank you for reading the article. Hope you learned something valuable today. And most importantly, stay safe guys 😷</p>
]]></content:encoded></item><item><title><![CDATA[Hoisting - JavaScript Concepts Simplified]]></title><description><![CDATA[Have you ever wondered how you are able to call a function in JS even before declaring it?
JavaScript is an interpreted programming language. An interpreter in the browser interprets each line of code and runs it. The interpreter follows a process ca...]]></description><link>https://blog.thisurathenuka.dev/hoisting-javascript-concepts-simplified</link><guid isPermaLink="true">https://blog.thisurathenuka.dev/hoisting-javascript-concepts-simplified</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[hosting]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[dev-diaries]]></category><dc:creator><![CDATA[Thisura Thenuka]]></dc:creator><pubDate>Sat, 18 Sep 2021 05:12:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1663608872377/B5TSnn-hd.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever wondered how you are able to call a function in JS even before declaring it?
JavaScript is an interpreted programming language. An interpreter in the browser interprets each line of code and runs it. The interpreter follows a process called <strong>Hoisting </strong>to make the aforementioned feature possible.</p>
<h1 id="heading-what-is-hoisting">What is Hoisting</h1>
<p>Hoisting is the process of moving the declarations of <strong>functions</strong>, <strong>variables </strong>and <strong>classes </strong>to the top of their scope before the code is executed. Let's discuss each one of these scenarios with examples.</p>
<h2 id="heading-function-hoisting">Function Hoisting</h2>
<pre><code class="lang-javascript"><span class="hljs-comment">//Before hoisting </span>
thisIsHuge()    <span class="hljs-comment">//Logs "That's what she said" to the console </span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">thisIsHuge</span>(<span class="hljs-params"></span>)</span>{ 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'That\'s what she said'</span>) 
}
</code></pre>
<p>Since the function is declared in the global scope, the interpreter moves the declaration of the function to the top of the code by hoisting</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">thisIsHuge</span>(<span class="hljs-params"></span>)</span>{ 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'That\'s what she said'</span>) 
} 
thisIsHuge()
</code></pre>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://media.giphy.com/media/2rWqXxuoqY9nP2Y1nf/giphy.gif">https://media.giphy.com/media/2rWqXxuoqY9nP2Y1nf/giphy.gif</a></div>
<h2 id="heading-variable-hoisting">Variable Hoisting</h2>
<p>There are 3 keywords that we can use to declare a variable in JS: <code>var</code>, <code>let</code> and <code>const</code>. Let's see how hoisting works for each one of them.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Using var keyword</span>
<span class="hljs-built_in">console</span>.log(x) <span class="hljs-comment">//Logs undefined to the console (Default initialization of var) </span>
<span class="hljs-keyword">var</span> x = <span class="hljs-number">10</span>
<span class="hljs-built_in">console</span>.log(x) <span class="hljs-comment">//Logs 10 to the console</span>

<span class="hljs-comment">//Using let keyword</span>
<span class="hljs-built_in">console</span>.log(y)  <span class="hljs-comment">//Throws ReferenceError: Cannot access 'y' before initialization</span>
<span class="hljs-keyword">let</span> y = <span class="hljs-number">20</span>

<span class="hljs-comment">//Using const keyword</span>
<span class="hljs-built_in">console</span>.log(z)  <span class="hljs-comment">//Throws ReferenceError: Cannot access 'z' before initialization</span>
<span class="hljs-keyword">const</span> z = <span class="hljs-number">30</span>
</code></pre>
<p>Variables declared using <code>let</code> and <code>const</code> keywords do not have a default initialization value.</p>
<h2 id="heading-class-hoisting"><code>class</code> Hoisting</h2>
<p>Even though, we can call a function before it is defined, we cannot construct an object before the class is defined.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">new</span> Car()); <span class="hljs-comment">//ReferenceError: Cannot access 'Car' before initialization</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span> </span>{
  <span class="hljs-keyword">constructor</span>(name, year) {
    <span class="hljs-built_in">this</span>.name = name;
    <span class="hljs-built_in">this</span>.year = year;
  }
}
</code></pre>
<h1 id="heading-summary">Summary</h1>
<p><strong>It is always a good coding practice to declare the variables at the top of the scope</strong></p>
<p>It's true that hoisting can be useful sometimes. But in the long run, it will end up creating more bugs. We should always declare the variables, classes and functions before using them.</p>
<h1 id="heading-further-reading">Further Reading</h1>
<ul>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting">MDN Docs on Hoisting</a> </p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/what-is-hoisting-in-javascript/">FreeCodeCamp article on Hoisting</a> </p>
</li>
<li><p><a target="_blank" href="https://www.digitalocean.com/community/tutorials/understanding-hoisting-in-javascript">Digital Ocean article on Hoisting</a> </p>
</li>
</ul>
<h1 id="heading-ciao">Ciao</h1>
<p>Thank you for reading my article. I hope you learned something valuable today. If you liked it, drop a like and subscribe to my blog. I’ll see you soon with my next article. Stay Safe 😷</p>
]]></content:encoded></item></channel></rss>