<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rafi Hasan on Medium]]></title>
        <description><![CDATA[Stories by Rafi Hasan on Medium]]></description>
        <link>https://medium.com/@hasan.rafi344?source=rss-b15dec7f35fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*R3rW67YVkILuJOUq</url>
            <title>Stories by Rafi Hasan on Medium</title>
            <link>https://medium.com/@hasan.rafi344?source=rss-b15dec7f35fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:10:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hasan.rafi344/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[You May Have Used Object Destructuring in JavaScript — But Do You Know Why You Need It?]]></title>
            <link>https://medium.com/@hasan.rafi344/you-may-have-used-object-destructuring-in-javascript-but-do-you-know-why-you-need-it-b8f825a707ed?source=rss-b15dec7f35fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8f825a707ed</guid>
            <category><![CDATA[object-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[object-destructuring]]></category>
            <dc:creator><![CDATA[Rafi Hasan]]></dc:creator>
            <pubDate>Mon, 08 Sep 2025 17:49:30 GMT</pubDate>
            <atom:updated>2025-09-08T17:49:30.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>You May Have Used Object Destructuring in JavaScript — But Do You Know <em>Why</em> You Need It?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*D_AblO4GpalgJEmZrx9mJA.jpeg" /><figcaption>Image from Unsplash</figcaption></figure><p>In this article, I’ll cover both the <strong>how</strong> (different types of object destructuring) and the <strong>why</strong> (real-world use cases that make your code cleaner, safer, and more maintainable).</p><h3>🔹 What is Object Destructuring?</h3><p>Object destructuring is a feature introduced in ES6 that lets you <strong>unpack values from objects</strong> and assign them directly to variables.<br>Instead of writing:</p><pre>const user = { name: &quot;Rafi&quot;, age: 23 };<br>const name = user.name;<br>const age = user.age;</pre><p>You can write:</p><pre>const { name, age } = user;</pre><p>It’s shorter, cleaner, and more powerful. Now let’s see the different ways you can use destructuring.</p><h3>🧩 Different Types of Object Destructuring</h3><h3>1. Property to Value</h3><p>Extract a single property directly.</p><pre>const user = { name: &quot;Rafi&quot;, age: 23 };<br>const { name } = user;<br><br>console.log(name); // &quot;Rafi&quot;</pre><h3>2. Multiple Properties</h3><p>Get several values at once.</p><pre>const user = { name: &quot;Rafi&quot;, age: 23, country: &quot;Bangladesh&quot; };<br>const { name, age } = user;<br><br>console.log(name, age); // &quot;Rafi&quot; 23</pre><h3>3. Default Value</h3><p>Provide fallbacks when properties are missing.</p><pre>const settings = { theme: &quot;dark&quot; };<br>const { theme, fontSize = 14 } = settings;<br><br>console.log(theme, fontSize); // &quot;dark&quot; 14</pre><h3>4. Alias (Renaming)</h3><p>Rename a property during destructuring.</p><pre>const user = { name: &quot;Rafi&quot;, age: 23 };<br>const { name: userName, age: userAge } = user;<br><br>console.log(userName, userAge); // &quot;Rafi&quot; 23</pre><h3>5. Deep Property (Nested)</h3><p>Extract from nested objects.</p><pre>const user = {<br>  name: &quot;Rafi&quot;,<br>  address: { city: &quot;Dhaka&quot;, zip: 1207 }<br>};<br><br>const { address: { city, zip } } = user;<br><br>console.log(city, zip); // &quot;Dhaka&quot; 1207</pre><h3>6. Dynamic Property Name</h3><p>Use variables as property keys.</p><pre>const key = &quot;age&quot;;<br>const user = { name: &quot;Rafi&quot;, age: 23 };<br><br>const { [key]: userAge } = user;<br><br>console.log(userAge); // 23</pre><h3>🎯 Why and When Should You Use Destructuring?</h3><p>Syntax alone isn’t enough — let’s see <strong>where destructuring shines in real-world scenarios</strong>.</p><h3>✅ 1. Cleaner Code When Extracting Data</h3><p>Instead of writing user.name, user.age, and so on, destructuring pulls out everything you need in one line.</p><h3>✅ 2. Function Parameters</h3><p>Pass objects into functions and destructure them directly, making the function signature self-explanatory.</p><pre>function greet({ name, age }) {<br>  console.log(`Hello ${name}, you are ${age} years old`);<br>}<br><br>greet({ name: &quot;Rafi&quot;, age: 23 });</pre><h3>✅ 3. Default Values for Safer Code</h3><p>Avoid undefined errors when properties are missing (common in API responses).</p><h3>✅ 4. Working with APIs (Nested Destructuring)</h3><p>Most API responses have deeply nested objects. Destructuring saves you from messy dot-chains.</p><pre>const response = {<br>  data: { user: { id: 1, username: &quot;rafi&quot; } }<br>};<br><br>const { data: { user: { username } } } = response;<br>console.log(username); // &quot;rafi&quot;</pre><h3>✅ 5. Renaming for Clarity</h3><p>Great when API fields aren’t descriptive or conflict with existing variables.</p><h3>✅ 6. Dynamic Keys</h3><p>When property names come from user input or runtime logic.</p><h3>✅ 7. Cleaner Loops</h3><p>When looping through arrays of objects, destructuring makes it easy to pick what you need.</p><pre>const users = [<br>  { name: &quot;Rafi&quot;, age: 23 },<br>  { name: &quot;Shams&quot;, age: 25 }<br>];<br><br>for (const { name, age } of users) {<br>  console.log(`${name} is ${age} years old`);<br>}</pre><h3>✅ 8. Module Imports</h3><p>Even imports use destructuring to grab only what you need.</p><pre>const { readFile } = require(&quot;fs&quot;);</pre><h3>🚀 Final Thoughts</h3><p>Object destructuring isn’t just about saving a few keystrokes — it’s about writing <strong>cleaner, safer, and more maintainable JavaScript</strong>.</p><p>Use it to:</p><ul><li>Extract only the data you need</li><li>Handle default values gracefully</li><li>Make function parameters self-documenting</li><li>Deal with messy nested API responses</li><li>Simplify loops and imports</li></ul><p>So next time you see or use destructuring, don’t just think “syntax sugar.” Think of it as a <strong>developer productivity tool</strong> that helps you write elegant, modern JavaScript.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8f825a707ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Git Push Rejected: How I Accidentally Exposed a Secret and Fixed It Like a Pro”]]></title>
            <link>https://medium.com/@hasan.rafi344/git-push-rejected-how-i-accidentally-exposed-a-secret-and-fixed-it-like-a-pro-23684c5125d4?source=rss-b15dec7f35fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/23684c5125d4</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git-push-fail]]></category>
            <category><![CDATA[environment-variables]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-issue]]></category>
            <dc:creator><![CDATA[Rafi Hasan]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 19:59:40 GMT</pubDate>
            <atom:updated>2025-08-11T19:59:40.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLKqtB4txaBTyokqfjlO9A.jpeg" /></figure><h3>Introduction</h3><p>Pushing code to GitHub is usually smooth sailing — until you accidentally commit sensitive secrets like API keys in your .env file. Then, GitHub&#39;s secret scanning blocks your push with scary warnings, leaving you stuck.</p><p>I faced this exact problem recently. In this post, I’ll walk you through why this happens and how to fix it safely with practical Git commands.</p><h3>Why Did My Push Fail?</h3><p>GitHub automatically scans every push for secrets — API keys, tokens, passwords — anywhere in your commit history. If it finds one, it <strong>blocks the push</strong> to protect you from accidental leaks.</p><p><strong>In my case, I had a Groq API key in my </strong><strong>.env file</strong> committed and pushed. GitHub rejected my push with this message:</p><blockquote>Push cannot contain secrets<em><br> </em>Location: .env in commit 5d15409…</blockquote><h3>Step 1: Stop Tracking the Secret File</h3><p>First, remove .env from Git tracking — it should never be in your repo.</p><pre>git rm --cached .env<br>echo &quot;.env&quot; &gt;&gt; .gitignore<br>git add .gitignore<br>git commit -m &quot;Stop tracking .env and add to .gitignore&quot;</pre><h3>Step 2: Remove the Secret from Git History</h3><p>Even after removing .env, the secret remains in past commits. You must <strong>rewrite your Git history</strong> to completely remove it.</p><p>The easiest way is to use <a href="https://github.com/newren/git-filter-repo">git-filter-repo</a>:</p><pre>pip install git-filter-repo<br><br>git filter-repo --path .env --invert-paths --force</pre><p>This removes .env from <em>all</em> commits.</p><blockquote><strong><em>Important:</em></strong><em> This command </em>removes your Git remote<em> for safety. You’ll need to re-add it next.</em></blockquote><h3>Step 3: Reconnect Remote and Force Push</h3><p>Now, reconnect your remote repository and force push the cleaned history:</p><pre>git remote add origin https://github.com/yourusername/yourrepo.git<br>git push origin main --force</pre><p>— — Force push is necessary because history has been rewritten.</p><h3>Step 4: Secure Your Secrets for Good</h3><ul><li>Always add .env (or any secret config) to .gitignore.</li><li>Use environment variables or secret managers to inject secrets in deployment.</li><li>Revoke and regenerate any exposed keys immediately.</li></ul><h3>Conclusion</h3><p>Accidentally committing secrets is a common developer hiccup — but don’t panic! By cleaning your Git history and using .gitignore wisely, you can keep your repo clean and your projects secure.</p><p>Follow these steps to recover and protect your codebase — your future self will thank you.</p><p>If you found this helpful, feel free to share!<br>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23684c5125d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Deep vs Shallow Copy in JavaScript: A Practical Guide with 1D & 2D Arrays]]></title>
            <link>https://medium.com/@hasan.rafi344/deep-vs-shallow-copy-in-javascript-a-practical-guide-with-1d-2d-arrays-3a70f7901e56?source=rss-b15dec7f35fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a70f7901e56</guid>
            <category><![CDATA[shallow-vs-deep-copy]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[deep-copies-javascript]]></category>
            <category><![CDATA[javascript-arrays]]></category>
            <category><![CDATA[shallow-copy]]></category>
            <dc:creator><![CDATA[Rafi Hasan]]></dc:creator>
            <pubDate>Mon, 11 Aug 2025 06:35:44 GMT</pubDate>
            <atom:updated>2025-08-11T06:35:44.930Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*cXF7qSCNUoDdLXbJ-Iob9w.png" /></figure><p>When working with arrays in JavaScript, copying them might seem straightforward — until unexpected bugs creep in. Understanding the difference between <strong>shallow</strong> and <strong>deep</strong> copies is essential, especially when dealing with nested arrays or objects.</p><p>Let’s break it down with examples you can test.</p><p>🧪 What Is a Shallow Copy?</p><p>A <strong>shallow copy</strong> duplicates the top-level structure of an array. But if the array contains nested arrays or objects, those inner references are <strong>shared</strong> between the original and the copy.</p><p>✅ Example: 1D Array (Safe with Shallow Copy)</p><pre>const original = [1, 2, 3];<br>const shallow = [...original]; // or original.slice()<br><br>shallow[0] = 99;<br>console.log(original); // [1, 2, 3] — unaffected</pre><p>⚠️ Example: 2D Array (Shared References)</p><pre>const original = [[1, 2], [3, 4]];<br>const shallow = [...original];<br><br>shallow[0][0] = 99;<br>console.log(original); // [[99, 2], [3, 4]] — original is mutated!<br><br>//Why? Because shallow[0] and original[0] point to the same inner array.</pre><p>🧬 What Is a Deep Copy?</p><p>A <strong>deep copy</strong> creates a new array and recursively copies all nested elements. This ensures complete separation between the original and the copy.</p><p>✅ Example: Deep Copy of 2D Array</p><pre>const original = [[1, 2], [3, 4]];<br>const deep = JSON.parse(JSON.stringify(original));<br><br>deep[0][0] = 99;<br>console.log(original); // [[1, 2], [3, 4]] — original is safe</pre><p><strong>Note: </strong>JSON.parse(JSON.stringify(...)) doesn’t handle functions, undefined, or circular references.</p><p>🧠 Modern Deep Copy: structuredClone()</p><p>If you’re using a modern browser or Node.js 17+, structuredClone() is a clean solution:</p><pre>const original = [[1, 2], [3, 4]];<br>const deep = structuredClone(original);<br><br>deep[1][1] = 99;<br>console.log(original); // [[1, 2], [3, 4]]</pre><p><strong><em>&gt; It supports Dates, Maps, Sets, and even circular structures.</em></strong></p><p><strong>Summary Table-&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1dyzIzNYRFqsv7zun8irzA.png" /></figure><p>✍️<strong> Final Thoughts</strong><br>If you’re working with simple arrays, shallow copies are fine. But once you dive into nested structures — like 2D arrays or objects inside arrays — deep copying is your safety net.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a70f7901e56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 Ways to Concatenate Strings in JavaScript — From Classic to Modern]]></title>
            <link>https://medium.com/@hasan.rafi344/7-ways-to-concatenate-strings-in-javascript-from-classic-to-modern-bb260500d77c?source=rss-b15dec7f35fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb260500d77c</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[string-in-javascript]]></category>
            <category><![CDATA[string-concatenation]]></category>
            <dc:creator><![CDATA[Rafi Hasan]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 17:32:15 GMT</pubDate>
            <atom:updated>2025-08-10T17:32:15.649Z</atom:updated>
            <content:encoded><![CDATA[<h3>7 Ways to Concatenate Strings in JavaScript — From Classic to Modern</h3><p>String concatenation is one of the most common tasks in JavaScript. Whether you’re merging names, building messages, or formatting output, JavaScript offers <strong>multiple ways</strong> to combine strings.</p><p>In this post, we’ll explore <strong>7 different methods</strong>, starting with old-school ES1 tricks and ending with modern ES6 syntax.</p><h3>1. += Concatenation (ES1)</h3><p>The oldest and most common way — simple, clear, works everywhere.</p><pre>const names = [&#39;Tom&#39;, &#39;Tim&#39;, &#39;Tin&#39;, &#39;Tik&#39;];<br>let result = &#39;&#39;;<br><br>for (let i = 0; i &lt; names.length; i++) {<br>    result += names[i];<br>}<br>console.log(result); // TomTimTinTik</pre><h3>2. .join() Method (ES1)</h3><p>If you already have an array, .join() is the cleanest.</p><pre>const names = [&#39;Tom&#39;, &#39;Tim&#39;, &#39;Tin&#39;, &#39;Tik&#39;];<br>let result = names.join(&#39;&#39;);<br>console.log(result); // TomTimTinTik<br></pre><h3>3. .reduce() Method (ES5)</h3><p>For functional programming fans.</p><pre>const fruits = [&#39;Apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;Date&#39;];<br>let result = fruits.reduce(function(acc, curr) {<br>    return acc + curr;<br>}, &#39;&#39;);<br>console.log(result); // AppleBananaCherryDate</pre><h3>4. forEach() Method (ES5)</h3><p>Readable and straightforward.</p><pre>const fruits = [&#39;Apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;Date&#39;];<br>let result = &#39;&#39;;<br>fruits.forEach(function(fruit) {<br>    result += fruit;<br>});<br>console.log(result); // AppleBananaCherryDate</pre><h3>5. .toString() + .replace() (ES1 &amp; ES3)</h3><p>A bit hacky, but fun to know.</p><pre>const fruits = [&#39;Apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;Date&#39;];<br>let result = fruits.toString().replace(/,/g, &#39;&#39;);<br>console.log(result); // AppleBananaCherryDate</pre><h3>6. for...of Loop (ES6)</h3><p>A cleaner looping syntax introduced in ES6.</p><pre>const fruits = [&#39;Apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;Date&#39;];<br>let result = &#39;&#39;;<br><br>for (const fruit of fruits) {<br>    result += fruit;<br>}<br>console.log(result); // AppleBananaCherryDate</pre><h3>7. Arrow Functions + Template Literals (ES6)</h3><p>Modern, compact, and readable.</p><pre>const fruits = [&#39;Apple&#39;, &#39;Banana&#39;, &#39;Cherry&#39;, &#39;Date&#39;];<br>let result = fruits.reduce((acc, curr) =&gt; `${acc}${curr}`, &#39;&#39;);<br>console.log(result); // AppleBananaCherryDate</pre><h3>Final Thoughts</h3><p>If you’re working in <strong>legacy environments</strong>, stick to .join() or += concatenation — they’ve been around since ES1 and work everywhere.<br>For <strong>modern projects</strong>, embrace ES6 syntax like for...of, arrow functions, and template literals for cleaner and more expressive code.</p><p>💡 <em>Tip:</em> When dealing with <strong>large amounts of string concatenation</strong>, methods like .join() can be more efficient than repeatedly using +=, because JavaScript engines can optimize array joining better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb260500d77c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>