<?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[devbeyondbeginner]]></title><description><![CDATA[Software Engineering practices that you can follow...]]></description><link>https://devbeyondbeginner.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 12:55:09 GMT</lastBuildDate><atom:link href="https://devbeyondbeginner.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Hidden Trap of Array.prototype.fill()]]></title><description><![CDATA[🚀 TLDR;
If your initialisation involves populating an array with non-primitive types (arrays, objects, sets, etc.), never use fill() as it creates a single instance of the array/object passed to it, and fills values of the array with its reference.
...]]></description><link>https://devbeyondbeginner.com/the-hidden-trap-of-arrayprototypefill</link><guid isPermaLink="true">https://devbeyondbeginner.com/the-hidden-trap-of-arrayprototypefill</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[bipin gosain]]></dc:creator><pubDate>Sat, 25 Oct 2025 09:27:17 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1761383843303/7edfc546-4153-4cab-bc1f-3bb2de330e56.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-tldr">🚀 TLDR;</h2>
<p>If your initialisation involves populating an array with non-primitive types (arrays, objects, sets, etc.), <strong>never</strong> use <code>fill()</code> as it creates a single instance of the array/object passed to it, and fills values of the array with its reference.</p>
<p>Use <code>Array.from()</code> with a mapping function to guarantee that every element is a unique, independent instance.</p>
<p>For your next interview problem or complex project, remember this rule—it might save you hours of painful debugging! Happy coding!</p>
<hr />
<p>When solving the Top K frequent problem using the bucket approach, I needed an array of N+1 unique slots, where N is the maximum possible frequency (<code>nums.length</code>). Each slot must be an independent array.</p>
<p>My initial line of code looked like this:</p>
<p>JavaScript</p>
<pre><code class="lang-plaintext">const maxFrequency = nums.length;
const buckets = new Array(maxFrequency + 1).fill([]);
</code></pre>
<h3 id="heading-what-actually-happens-shared-references">🧐 What Actually Happens: Shared References</h3>
<p>The core issue is that <code>fill()</code> only accepts a single value as an argument. When that value is a <strong>non-primitive type</strong> (like an array or an object), JavaScript does the following:</p>
<ol>
<li><p>It creates <strong>one single empty array</strong> in memory: <code>[]</code>.</p>
</li>
<li><p>It then puts a <strong>reference</strong> to this <em>single, same array</em> into every single index of the <code>buckets</code> array.</p>
</li>
</ol>
<p><strong>The Crux:</strong> When my frequency map told me to place a number with frequency 3 into <code>buckets[3]</code>, I wrote:</p>
<p>JavaScript</p>
<pre><code class="lang-plaintext">buckets[3].push(num); // I thought I was only affecting bucket 3...
</code></pre>
<p>But because <code>buckets[3]</code>, <code>buckets[0]</code>, <code>buckets[1]</code>, and all the others were all pointing to the <strong>exact same array object</strong> in memory, <strong>every bucket got the number!</strong> My entire bucket structure was completely corrupted. This is why my "Top K" solution was not working correctly for all test cases.</p>
<hr />
<h2 id="heading-the-solution-arrayfrom-length-gt">✅ The Solution: <code>Array.from({ length }, () =&gt; [])</code></h2>
<p>The correct way to initialize an array where every element needs to be a <strong>unique instance</strong> of an object (like a unique bucket array) is to use the <code>Array.from()</code> method with a mapping function.</p>
<p>JavaScript</p>
<pre><code class="lang-plaintext">const maxFrequency = nums.length;
const buckets = Array.from({ length: maxFrequency + 1 }, () =&gt; []);
</code></pre>
<h3 id="heading-why-this-works-the-map-function-creates-unique-instances">💡 Why This Works: The Map Function Creates Unique Instances</h3>
<p><code>Array.from()</code> is designed to create a new array from an iterable or array-like object (like <code>{ length: N }</code>). Critically, the second argument is a <strong>map function</strong> that is executed for every index.</p>
<p>The map function here is <code>() =&gt; []</code>. For each of the N+1 positions:</p>
<ol>
<li><p><code>Array.from()</code> executes <code>() =&gt; []</code>.</p>
</li>
<li><p>The function returns a <strong>brand new, unique empty array instance</strong>.</p>
</li>
</ol>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Method</strong></td><td><strong>Creates</strong></td><td><strong>Resulting References</strong></td><td><strong>Impact on Buckets</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>fill([])</code></td><td><strong>One</strong> <code>[]</code></td><td>All elements point to the <strong>same</strong> array.</td><td>Modifying one bucket affects <strong>all</strong> buckets.</td></tr>
<tr>
<td><code>Array.from(..., () =&gt; [])</code></td><td><strong>N</strong> <code>[]</code> instances</td><td>Each element points to a <strong>unique</strong> array.</td><td>Modifying one bucket affects <strong>only that one</strong> bucket.</td></tr>
</tbody>
</table>
</div><p>Switching to <code>Array.from()</code> instantly fixed the issue. My buckets were properly isolated, my logic worked, and I finally got that sweet "Accepted" status.</p>
]]></content:encoded></item><item><title><![CDATA[Introduction to AWS CDK: When to Use It Over Terraform]]></title><description><![CDATA[When I first started automating infrastructure on AWS, I didn’t want to deal with writing giant YAML or JSON templates by hand. That’s where the AWS Cloud Development Kit (CDK) clicked for me. CDK lets me write infrastructure in TypeScript, which is ...]]></description><link>https://devbeyondbeginner.com/introduction-to-aws-cdk-when-to-use-it-over-terraform</link><guid isPermaLink="true">https://devbeyondbeginner.com/introduction-to-aws-cdk-when-to-use-it-over-terraform</guid><category><![CDATA[CDK]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[coding]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[automation]]></category><dc:creator><![CDATA[bipin gosain]]></dc:creator><pubDate>Wed, 03 Sep 2025 05:40:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756877960354/588316bc-3afa-4cb3-bc12-f5c788a0bf1d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When I first started automating infrastructure on AWS, I didn’t want to deal with writing giant YAML or JSON templates by hand. That’s where the <strong>AWS Cloud Development Kit (CDK)</strong> clicked for me. CDK lets me write infrastructure in TypeScript, which is the same language I use for most of my application code. It feels natural, it’s expressive, and I get to use the full power of a programming language — loops, conditions, functions — to define my infra.</p>
<h2 id="heading-what-is-cdk">What is CDK?</h2>
<p>At its core, CDK is an <strong>Infrastructure as Code (IaC) framework</strong>. Instead of manually writing CloudFormation templates, you define your resources (like S3 buckets, Lambda functions, DynamoDB tables) using code. CDK then compiles that into CloudFormation under the hood and handles the deployment.</p>
<p>So in short:</p>
<ul>
<li><p>I write infra in code.</p>
</li>
<li><p>CDK converts it into CloudFormation.</p>
</li>
<li><p>CloudFormation applies it to AWS.</p>
</li>
</ul>
<p>That abstraction layer is what makes CDK so convenient.</p>
<h2 id="heading-how-does-terraform-fit-in">How Does Terraform Fit In?</h2>
<p>I haven’t used Terraform myself, but I often hear it compared with CDK. The way I see it:</p>
<ul>
<li><p><strong>Terraform</strong> is a widely used, declarative tool that works across multiple cloud providers.</p>
</li>
<li><p><strong>CDK</strong> is tightly integrated with AWS and gives you the flexibility of coding infra in a real language.</p>
</li>
</ul>
<p>If your team works across AWS + Azure + GCP, Terraform might make more sense. But if you’re deep in AWS (like me), CDK feels like a natural extension of app development.</p>
<h2 id="heading-cdk-in-5-basic-commands">CDK in 5 Basic Commands</h2>
<p>The workflow with CDK is super simple. Most of the time I only use these five commands:</p>
<ol>
<li><p><code>cdk init</code> – start a new project (I usually pick TypeScript).</p>
</li>
<li><p><code>cdk synth</code> – see the CloudFormation template CDK generates.</p>
</li>
<li><p><code>cdk diff</code> – check what’s about to change in your infra before deploying.</p>
</li>
<li><p><code>cdk deploy</code> – apply the changes to AWS.</p>
</li>
<li><p><code>cdk destroy</code> – tear it all down if you don’t need it anymore.</p>
</li>
</ol>
<p>That’s basically the lifecycle — define → preview → deploy → clean up.</p>
<h2 id="heading-why-i-prefer-cdk">Why I Prefer CDK</h2>
<p>For me, CDK works best when:</p>
<ul>
<li><p>I want my <strong>infra and application logic in the same language</strong>.</p>
</li>
<li><p>I need <strong>dynamic infra generation</strong> (like looping through configs to create multiple S3 buckets).</p>
</li>
<li><p>I want <strong>strong AWS-native support</strong> without extra layers.</p>
</li>
</ul>
<p>The productivity boost I get from not context-switching between TypeScript and HCL/YAML is huge.</p>
]]></content:encoded></item><item><title><![CDATA[Skills Every MERN Stack Engineer Should Know (Beyond Just React & Express)]]></title><description><![CDATA[Hey folks 👋,One thing I’ve noticed is that when people say they “know MERN,” it often just means basic React + a couple of Express routes. But in real projects, that’s only the starting point.
If you want to actually thrive as a MERN engineer, here ...]]></description><link>https://devbeyondbeginner.com/skills-every-mern-stack-engineer-should-know-beyond-just-react-and-express</link><guid isPermaLink="true">https://devbeyondbeginner.com/skills-every-mern-stack-engineer-should-know-beyond-just-react-and-express</guid><category><![CDATA[MERN Stack]]></category><category><![CDATA[React]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[ci-cd]]></category><dc:creator><![CDATA[bipin gosain]]></dc:creator><pubDate>Sat, 30 Aug 2025 07:02:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756537299861/da017d5d-059e-4962-a1ff-c2e4aa9414f1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey folks 👋,<br />One thing I’ve noticed is that when people say they “know MERN,” it often just means <em>basic React + a couple of Express routes</em>. But in real projects, that’s only the starting point.</p>
<p>If you want to actually thrive as a MERN engineer, here are a few skills worth investing in (beyond the basics):</p>
<hr />
<h3 id="heading-1-state-management-that-scales">1. State Management That Scales</h3>
<p><code>useState</code> and <code>useEffect</code> will only get you so far. For bigger apps, tools like <strong>Redux Toolkit, React Query, or Zustand</strong> make state predictable, manageable, and easier to debug.</p>
<hr />
<h3 id="heading-2-authentication-amp-authorization">2. Authentication &amp; Authorization</h3>
<p>Almost every app needs login and permissions. Learn <strong>JWTs, sessions, OAuth, role-based access</strong>, and how to integrate with services like Auth0 or Firebase.</p>
<hr />
<h3 id="heading-3-mongodb-beyond-crud">3. MongoDB Beyond CRUD</h3>
<p>Knowing <code>find()</code> isn’t enough. You should understand:</p>
<ul>
<li><p>Schema design (when to embed vs reference)</p>
</li>
<li><p><strong>Indexes &amp; Aggregations</strong> for performance</p>
</li>
<li><p>Transactions when multiple collections are involved</p>
</li>
</ul>
<hr />
<h3 id="heading-4-writing-better-apis">4. Writing Better APIs</h3>
<p>It’s not just <code>app.get("/")</code>. Think about:</p>
<ul>
<li><p>API versioning (<code>/v1</code>, <code>/v2</code>)</p>
</li>
<li><p>Input validation</p>
</li>
<li><p>Rate limiting and error handling</p>
</li>
<li><p>Maybe even exploring <strong>GraphQL</strong></p>
</li>
</ul>
<hr />
<h3 id="heading-5-deployment-amp-devops-basics">5. Deployment &amp; DevOps Basics</h3>
<p>You’ll need to ship your app somewhere. At minimum:</p>
<ul>
<li><p><strong>Dockerize</strong> your app</p>
</li>
<li><p>Deploy to AWS, Vercel, or Netlify</p>
</li>
<li><p>Automate with <strong>CI/CD pipelines</strong></p>
</li>
</ul>
<hr />
<h3 id="heading-6-security-amp-performance">6. Security &amp; Performance</h3>
<p>Real-world apps break if you don’t care about these:</p>
<ul>
<li><p>Preventing XSS, CSRF, and SQL/NoSQL injections</p>
</li>
<li><p>Optimizing React with lazy loading &amp; memoization</p>
</li>
<li><p>Using <strong>Redis or caching layers</strong></p>
</li>
</ul>
<hr />
<h3 id="heading-7-testing-dont-skip-this">7. Testing (Don’t Skip This)</h3>
<p>Jest, React Testing Library, and Supertest can save you hours of debugging and help build trust in your code.</p>
<hr />
<h3 id="heading-wrapping-up">Wrapping Up</h3>
<p>Being a MERN engineer is not about “just React and Express.” It’s about building <strong>scalable, secure, production-ready systems</strong>. Once you get comfortable with these extra skills, you’ll realize how much more confident you feel tackling real projects.</p>
<p>That’s my take — curious to know, what advanced MERN skill has helped <em>you</em> the most? 🚀</p>
]]></content:encoded></item></channel></rss>