<?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 Malcon Lobo on Medium]]></title>
        <description><![CDATA[Stories by Malcon Lobo on Medium]]></description>
        <link>https://medium.com/@lobomalcon?source=rss-592b00df70fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BcNK7etvvRITZoM1EUi1sw.jpeg</url>
            <title>Stories by Malcon Lobo on Medium</title>
            <link>https://medium.com/@lobomalcon?source=rss-592b00df70fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:37:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lobomalcon/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[ Stop Building Custom File Uploaders: Why I Built a Framework-Agnostic, Multi-Cloud Multipart…]]></title>
            <link>https://medium.com/@lobomalcon/stop-building-custom-file-uploaders-why-i-built-a-framework-agnostic-multi-cloud-multipart-45dbc6d19a38?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/45dbc6d19a38</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 11:42:33 GMT</pubDate>
            <atom:updated>2026-06-25T06:55:19.058Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Stop Building Custom File Uploaders: Why I Built a Framework-Agnostic, Multi-Cloud Multipart Uploader for the Browser</h3><figure><img alt="Multipart upload in progress" src="https://cdn-images-1.medium.com/max/1024/1*6P41FwohSsKYLsMoUF-a9A.png" /><figcaption>Multipart upload in progress…</figcaption></figure><p>If you’ve spent any time working on modern web applications, you’ve inevitably hit the “large file upload” problem.</p><p>Uploading a 50KB avatar image is trivial. A single fetch or axios PUT request to a pre-signed URL does the job perfectly. But what happens when your users start uploading 500MB video recordings, 2GB high-resolution 3D models, or massive enterprise database backups?</p><p>Suddenly, your simple PUT request becomes a nightmare:</p><ul><li><strong>Browser Timeouts:</strong> A single long-running HTTP request over a standard home network inevitably times out.</li><li><strong>Memory Bloat:</strong> Loading a 2GB file entirely into RAM just to send it over the wire crashes older devices and mobile browsers.</li><li><strong>Fragile Connections:</strong> If a user’s Wi-Fi drops for three seconds at 99%, the entire 2GB upload fails, forcing them to start all over again from 0%.</li></ul><p>I was looking for a robust multipart upload solution that would work seamlessly in the browser without requiring me to expose my cloud storage keys in the frontend code. When I couldn’t find a clean, secure package that did this out of the box — I decided to build it myself. 🚀</p><p>I built <strong>cloud-multipart-uploader</strong>—a lightweight, highly concurrent, framework-agnostic uploader library that works flawlessly across AWS S3, Azure Blob Storage, and Google Cloud Storage.</p><h3>🔗 Secure Callback Architecture</h3><p>The core design revolves around a powerful adapter pattern. You simply pass your backend API endpoints (for generating presigned URLs and stitching chunks) into the uploader as clean async callbacks. This keeps your secret keys 100% secure on your backend, allowing your frontend code to remain completely decoupled from cloud authentication and focus solely on high-performance chunk streaming!</p><p>Here is a deep dive into the architecture of how it works, and why it might be the last upload library you ever need to install.</p><h3>🏗️ The Architectural Pillars</h3><p>When designing cloud-multipart-uploader, I established four strict architectural rules:</p><ol><li><strong>Zero Framework Lock-in:</strong> It must be 100% vanilla TypeScript/JavaScript. No dependencies on React, Vue, or Angular.</li><li><strong>Highly Concurrent:</strong> It must upload slices of the file in parallel to maximize the user’s bandwidth.</li><li><strong>Bulletproof Retries:</strong> It must gracefully handle spotty mobile network drops without failing the entire upload.</li><li><strong>Cloud Agnostic &amp; Secure:</strong> It must support AWS, Azure, and GCP out of the box, without <em>ever</em> exposing secret cloud credentials in the browser.</li></ol><h3>1. The Concurrency Engine (Without the Bloat)</h3><p>To achieve blazing-fast upload speeds, you have to slice the file into small chunks (e.g., 5MB) and upload multiple chunks simultaneously.</p><p>Most libraries solve concurrency by bundling external helper packages like p-limit. I wanted to keep the bundle size extremely lightweight, so I built a native TypeScript concurrency engine from scratch.</p><p>Instead of flooding the browser’s network queue with 100 simultaneous requests, our custom limiter maintains a strict execution pool (defaulting to 3 concurrent workers). As soon as Chunk 1 finishes, Chunk 4 instantly takes its place in the pool, keeping bandwidth utilization at absolute peak efficiency without causing browser UI lag.</p><h3>2. Bulletproof Retries: Exponential Backoff with Full Jitter</h3><p>What happens when a user is uploading a large video while riding a train, and their cellular connection briefly drops?</p><p>If an upload chunk fails, instantly retrying it usually results in another immediate failure. If you have 3 concurrent chunks fail simultaneously, and they all retry simultaneously 1 second later, they collide and create a massive network bottleneck.</p><p>To solve this, cloud-multipart-uploader implements an industry best-practice algorithm: <strong>Exponential Backoff with Full Jitter</strong>.</p><pre>// How the retry delay is calculated under the hood:<br>const baseDelay = Math.pow(2, attempt) * 1000;<br>const jitter = Math.random() * 1000;<br>await delay(baseDelay + jitter);</pre><p>Each time a chunk fails, the wait time doubles, and a random millisecond offset (“jitter”) is added.</p><ul><li><strong>1st Retry:</strong> ~1 to 2 seconds</li><li><strong>2nd Retry:</strong> ~2 to 3 seconds</li><li><strong>3rd Retry:</strong> ~4 to 5 seconds</li></ul><p>By adding random jitter, the failing chunks naturally stagger themselves so they don’t flood the recovering network connection at the exact same millisecond.</p><h3>3. The Pluggable Adapter Pattern (AWS, Azure, GCP)</h3><p>The hardest part of creating a multi-cloud library is that every cloud provider handles multipart uploads completely differently:</p><ul><li><strong>AWS S3:</strong> Expects an UploadId, requires a unique Presigned URL for each part, and returns an ETag header that must be sent back to stitch the file together.</li><li><strong>Azure Blob Storage:</strong> Uses a single Shared Access Signature (SAS) URL, expects chunks to be uploaded as “Blocks” with unique base64 BlockIds, and requires a final commit of the block list.</li><li><strong>Google Cloud Storage (GCP):</strong> Uses a native “Resumable Upload Session URL” where chunks are uploaded via HTTP Content-Range headers.</li></ul><p>Furthermore, <strong>you can never safely store your secret cloud API keys in the frontend</strong>.</p><p>To bridge this gap, cloud-multipart-uploader uses a powerful <strong>Adapter Pattern</strong> driven entirely by asynchronous callbacks. The library doesn&#39;t care how you communicate with your backend; it simply executes your callbacks at the exact right moment in the lifecycle.</p><h3>💻 Seeing it in Action (AWS S3 Example)</h3><figure><img alt="Multipart upload in progress" src="https://cdn-images-1.medium.com/max/1024/1*S34tLwu7n27-Q-PQGd2xHA.gif" /><figcaption>Simulating a complete network blackout at 46%: The exponential backoff retry engine gracefully halts, waits for reconnection, and successfully resumes the parallel streams to reach 100% upload completion.</figcaption></figure><h3><strong>📦 Installation</strong></h3><p>Here is how beautifully simple it is to implement in your frontend application:</p><figure><img alt="Cloud Multipart Uploader" src="https://cdn-images-1.medium.com/max/1024/1*d-2YBbX1twvgx3fA5K47HA.png" /></figure><pre>npm install cloud-multipart-uploader</pre><pre>import { MultipartUploader, AWSAdapter } from &#39;cloud-multipart-uploader&#39;;<br><br>// 1. Configure the Adapter to talk to your secure backend<br>const awsAdapter = new AWSAdapter({<br>  // Called before the upload starts. Fetch your Presigned URLs here.<br>  getUploadContext: async (file) =&gt; {<br>    const response = await fetch(&#39;/api/upload/initiate&#39;, {<br>      method: &#39;POST&#39;,<br>      body: JSON.stringify({ filename: file.name, size: file.size })<br>    });<br>    return await response.json(); // Expected: { uploadId, fileKey, presignedUrls: [...] }<br>  },<br>  <br>  // Called after all chunks succeed. Tell your backend to finalize the file in S3.<br>  completeMultipartUpload: async (context, parts) =&gt; {<br>    await fetch(&#39;/api/upload/complete&#39;, {<br>      method: &#39;POST&#39;,<br>      body: JSON.stringify({<br>        uploadId: context.uploadId,<br>        fileKey: context.fileKey,<br>        parts // Array of { ETag, PartNumber }<br>      })<br>    });<br>  }<br>});<br><br>// 2. Initialize the engine<br>const uploader = new MultipartUploader(awsAdapter, {<br>  chunkSize: 5 * 1024 * 1024, // 5MB slices<br>  maxConcurrency: 3,          // 3 parallel streams<br>  maxRetries: 5,              // Up to 5 exponential backoff retries per chunk<br>  onProgress: ({ loaded, total }) =&gt; {<br>    console.log(`Upload Progress: ${Math.round((loaded / total) * 100)}%`);<br>  }<br>});<br><br>// 3. Execute!<br>const file = document.getElementById(&#39;file-input&#39;).files[0];<br>await uploader.upload(file);<br>console.log(&quot;Upload complete! 🎉&quot;);</pre><h3>🤝 Open Source &amp; Enterprise Ready</h3><p>cloud-multipart-uploader is fully open-source and MIT licensed.</p><p>Whether you are building a lightweight startup MVP on AWS S3, migrating to Azure Blob Storage, or operating in a highly secure enterprise environment using on-premise solutions like <strong>MinIO</strong> or <strong>Ceph</strong>, this library gives you the foundation you need without the headache.</p><ul><li><strong>NPM:</strong> <a href="https://www.npmjs.com/package/cloud-multipart-uploader">cloud-multipart-uploader</a></li><li><strong>GitHub:</strong> <a href="https://github.com/malconlobo/cloud-multipart-uploader">malconlobo/cloud-multipart-uploader</a></li><li><strong>LinkedIn:</strong> <a href="https://www.linkedin.com/in/malcon-lobo-384010137">Connect with me on LinkedIn</a></li></ul><p>If you found this article useful, I’d be incredibly grateful if you left a 👏 (you can clap up to 50 times on Medium!) and gave the repo a ⭐️ on GitHub! Let me know in the comments how you handle large file uploads in your applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45dbc6d19a38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ JS Unlocked #5: Demystifying Closures in JavaScript]]></title>
            <link>https://medium.com/@lobomalcon/js-unlocked-5-demystifying-closures-in-javascript-0e6847f0e8ad?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e6847f0e8ad</guid>
            <category><![CDATA[closure]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Tue, 27 May 2025 14:59:54 GMT</pubDate>
            <atom:updated>2025-05-27T14:59:54.148Z</atom:updated>
            <content:encoded><![CDATA[<p>Closures are often labeled as one of the trickiest concepts to grasp in JavaScript — but once they <em>click</em>, they unlock a whole new level of understanding.</p><p>In this post, we’ll explore closures deeply, from what they are to why they matter, how they’re formed, and where they’re used in real-world code.</p><h3>📦 What Is a Closure?</h3><p>A <strong>closure</strong> is formed when a function “remembers” the variables from its <strong>outer lexical scope</strong>, even after that outer function has finished executing.</p><p>In simple terms:</p><blockquote><strong><em>Functions in JavaScript close over their surrounding scope.</em></strong></blockquote><h3>🔄 A Simple Example</h3><pre>function outer() {<br>  const name = &quot;JS Unlocked&quot;;<br>  return function inner() {<br>    console.log(`Hello from ${name}`);<br>  };<br>}<br><br>const greet = outer(); // &#39;outer&#39; finishes execution<br>greet(); // Hello from JS Unlocked</pre><p>Even though outer() has returned, the inner() function <strong>remembers</strong> the variable name — this is a closure in action.</p><h3>🧠 Why Are Closures Important?</h3><p>Closures let us:</p><ul><li><strong>Maintain state</strong> between function calls</li><li><strong>Create private variables</strong></li><li><strong>Build factory and callback functions</strong></li><li><strong>Enable data encapsulation</strong></li></ul><p>They form the <strong>backbone</strong> of many advanced patterns like currying, function factories, and module patterns.</p><h3>🔐 Closures and Scope Chain</h3><p>A closure holds a <strong>reference</strong> to variables in its <strong>lexical scope</strong>, not copies. So if those variables change, the closure reflects those changes.</p><pre>function counter() {<br>  let count = 0;<br>  return function increment() {<br>    count++;<br>    console.log(count);<br>  };<br>}<br><br>const inc = counter();<br>inc(); // 1<br>inc(); // 2</pre><p>Each call to inc() accesses and updates the same count variable — thanks to closure.</p><h3>🧪 Real-World Use Cases</h3><h3>✅ Creating Private Variables</h3><pre>function createUser() {<br>  let score = 0;<br>  return {<br>    increment: () =&gt; score++,<br>    getScore: () =&gt; score,<br>  };<br>}<br><br>const user = createUser();<br>user.increment();<br>console.log(user.getScore()); // 1</pre><p>No external access to score — it’s private inside the closure.</p><h3>✅ Event Handlers &amp; Callbacks</h3><pre>function setupButton() {<br>  let clicked = false;<br>  document.querySelector(&quot;button&quot;).addEventListener(&quot;click&quot;, function () {<br>    if (!clicked) {<br>      alert(&quot;First click!&quot;);<br>      clicked = true;<br>    }<br>  });<br>}</pre><p>The inner function retains access to clicked via closure.</p><h3>🧰 Common Mistakes</h3><h3>❌ Using var in Loops</h3><pre>for (var i = 0; i &lt; 3; i++) {<br>  setTimeout(() =&gt; console.log(i), 100);<br>}<br>// Output: 3, 3, 3 — not 0, 1, 2</pre><p>Why? Because closures capture i by reference, and by the time setTimeout runs, i is 3.</p><p>✅ Use let instead to create a new binding on each iteration.</p><h3>✅ Summary — TL;DR</h3><pre>| Concept       | Explanation                                                             |<br>|---------------|-------------------------------------------------------------------------|<br>| Closure       | A function remembering variables from its lexical scope after execution |<br>| Scope Chain   | Enables closures by preserving reference to outer variables             |<br>| Uses          | Private variables, function factories, async callbacks, data encaps.    |<br>| Real-world    | Counters, event handlers, modules, memoization, etc.                    |</pre><h3>🔭 What’s Next?</h3><p>In the next part of <strong>JS Unlocked</strong>, we’ll explore <strong>JavaScript’s memory model</strong> — how closures impact memory, the concept of <strong>garbage collection</strong>, and how to avoid memory leaks with long-living closures.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e6847f0e8ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ JS Unlocked #4 — Understanding the Scope Chain in JavaScript]]></title>
            <link>https://medium.com/@lobomalcon/js-unlocked-4-understanding-the-scope-chain-in-javascript-e352bbfc93ca?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/e352bbfc93ca</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[js-unlocked]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Sun, 04 May 2025 08:23:51 GMT</pubDate>
            <atom:updated>2025-05-04T08:23:51.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>🔓 JS Unlocked #4 — Understanding the Scope Chain in JavaScript</h3><p>If you’ve ever been confused about <strong>how JavaScript knows where to find your variables</strong>, you’re not alone. The secret lies in something called the <strong>Scope Chain</strong> — a fundamental concept that every JavaScript developer needs to understand to debug effectively and write cleaner code.</p><p>In this post, we’ll break it all down:</p><ul><li>🧠 What is the Scope Chain?</li><li>🧭 How JavaScript resolves variables</li><li>🧵 Lexical Scope and how it’s different from dynamic scope</li><li>📦 Real-world analogies to bring the concept to life</li><li>🧪 Code examples and visual diagrams</li></ul><h3>🔍 What is the Scope Chain?</h3><p>In JavaScript, <strong>scope</strong> defines where variables can be accessed from. The <strong>scope chain</strong> is how JavaScript looks up variables when executing your code.</p><p>When you try to access a variable, JavaScript:</p><ol><li>First checks the current function’s local scope.</li><li>Then checks the outer (parent) function’s scope.</li><li>Then continues this process up to the <strong>global scope</strong>.</li></ol><p>This chain of scopes forms the <strong>scope chain</strong>.</p><h3>🧵 Lexical Scope (aka Static Scope)</h3><p>JavaScript uses <strong>lexical scoping</strong>, meaning the structure of scopes is determined at <strong>code-writing time</strong>, not run-time.</p><pre>function outer() {<br>  const outerVar = &quot;I&#39;m from outer&quot;;</pre><pre>function inner() {<br>    console.log(outerVar); // ✅ Accessible due to lexical scope<br>  }</pre><pre>inner();<br>}<br>outer();</pre><p>Even though outerVar is not defined inside inner(), it’s accessible because inner() is <strong>lexically inside</strong> outer().</p><h3>🧩 Real-World Analogy: Boxes Inside Boxes</h3><p>Imagine each function as a <strong>box</strong>.</p><ul><li>A variable lookup is like looking for a key inside a box.</li><li>If the key isn’t there, you move to the outer box… and so on, until you either find it or reach the global box.</li></ul><p>This nesting of boxes is your <strong>scope chain</strong>.</p><h3>⚠️ Shadowing and Pitfalls</h3><p>Variable <strong>shadowing</strong> occurs when a variable in a nested scope has the same name as one in an outer scope.</p><pre>const name = &quot;Alice&quot;;</pre><pre>function greet() {<br>  const name = &quot;Bob&quot;;<br>  console.log(name); // prints &quot;Bob&quot;, not &quot;Alice&quot;<br>}</pre><p>The inner name <strong>shadows</strong> the outer one. The scope chain stops at the first match.</p><h3>🧪 Visual Diagram</h3><p>Here’s a simplified illustration:</p><pre>Global Scope<br>   └── outer()<br>         └── inner()</pre><p>When inner() accesses a variable:</p><ul><li>JavaScript checks inner&#39;s scope.</li><li>If not found, goes to outer&#39;s scope.</li><li>Still not found? Goes to global.</li></ul><h3>✅ Summary — TL;DR</h3><pre>| Concept        | Description                                                                 |<br>|----------------|-----------------------------------------------------------------------------|<br>| Scope          | The region in code where a variable can be accessed                         |<br>| Scope Chain    | How JavaScript looks for variables through nested scopes, up to global      |<br>| Lexical Scope  | Scope defined by where code is written, not where it runs                   |<br>| Shadowing      | A local variable with the same name as one in an outer scope takes priority |</pre><h3>🔜 What’s Next?</h3><p>Next up, we’ll zoom in on <strong>Closures</strong> — the natural consequence of understanding the scope chain. You’ll learn how JavaScript functions can remember variables from their parent scope even after the outer function has finished executing.</p><p>Closures are one of the most powerful and mind-bending features in JavaScript — don’t miss it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e352bbfc93ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ JS Unlocked #3: Behind the Scenes — Execution Context & Call Stack in JavaScript]]></title>
            <link>https://medium.com/@lobomalcon/js-unlocked-3-behind-the-scenes-execution-context-call-stack-in-javascript-c2b712d4988b?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2b712d4988b</guid>
            <category><![CDATA[programming-concepts]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[execution-context]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 16:21:02 GMT</pubDate>
            <atom:updated>2025-04-23T16:21:02.864Z</atom:updated>
            <content:encoded><![CDATA[<h3>🔓 JS Unlocked #3: Behind the Scenes — Execution Context &amp; Call Stack in JavaScript</h3><p>JavaScript might seem like magic sometimes — but under the hood, it’s powered by a predictable and fascinating engine. In this post, we’re going to demystify two key pieces: the <strong>Execution Context</strong> and the <strong>Call Stack</strong>.</p><p>Whether you’re trying to understand how variables are processed, how functions are executed, or why some errors occur, this post is your roadmap.</p><h3>📍 Quick Recap</h3><p>In the previous posts, we covered:</p><ul><li>var, let, and const</li><li><strong>Hoisting</strong> and the <strong>Temporal Dead Zone</strong></li></ul><p>Now, let’s look at the engine that drives all of that behavior: the Execution Context.</p><h3>🔧 What Is an Execution Context?</h3><p>Every time JavaScript runs code, it does so inside an <strong>execution context</strong>. This is the environment in which the code is evaluated and executed.</p><p>There are three main types:</p><ul><li>🌐 <strong>Global Execution Context (GEC)</strong> — Created when your JS file first runs</li><li>🔁 <strong>Function Execution Contexts (FEC)</strong> — Created each time a function is called</li><li>🧪 <strong>Eval Execution Context</strong> — Created inside the eval() function (rarely used)</li></ul><p>Each context has two phases:</p><ol><li><strong>Creation Phase</strong> — where the scope, variables, and functions are set up</li><li><strong>Execution Phase</strong> — where the code actually runs</li></ol><h3>🌍 Global Execution Context</h3><p>The GEC is created once when your script starts running. It’s the default or base context.</p><p>Here’s what it does:</p><ul><li>Sets up the global this keyword</li><li>Creates a global object (window in browsers, global in Node.js)</li><li>Allocates memory for variables and functions (this is where hoisting happens)</li></ul><p><strong>Real-world analogy:</strong><br> Think of the GEC as the main stage in a theater production. All characters (functions and variables) are introduced here. The show can have many scenes (functions), but they all begin on this stage.</p><h3>🔁 Function Execution Contexts</h3><p>Each time a function is called, a <strong>new execution context</strong> is created — independent of others.</p><p>What it contains:</p><ul><li>Local variables defined inside the function</li><li>A reference to the outer environment (scope chain)</li><li>The value of this for that function call</li></ul><p><strong>These contexts are stacked — and that’s where the call stack comes in.</strong></p><h3>🧱 The Call Stack</h3><p>JavaScript is <strong>single-threaded</strong>, meaning it can only execute one piece of code at a time.</p><p>To manage what code runs and when, JavaScript uses a <strong>call stack</strong>. It’s a <strong>LIFO</strong> structure — <em>Last In, First Out</em>.</p><h3>🪜 Visualizing the Stack:</h3><pre>function greet() {<br>  console.log(&quot;Hello&quot;);<br>}<br><br>function start() {<br>  greet();<br>}<br><br>start();</pre><p>➡️ Here’s what happens:</p><ol><li>GEC is created</li><li>start() is added to the stack</li><li>greet() is called and added to the stack</li><li>console.log() runs, then greet() is popped</li><li>start() is popped</li><li>The stack is empty again</li></ol><p><strong>Real-world analogy:</strong><br> Imagine stacking dinner plates — you always remove the top one first. That’s how JavaScript removes functions from the call stack.</p><h3>🧠 Why It Matters</h3><p>Understanding the <strong>execution context</strong> and <strong>call stack</strong> helps you:</p><ul><li>Predict variable behavior</li><li>Write cleaner, more modular code</li><li>Debug stack overflow or recursion issues</li><li>Prepare for more complex async patterns (coming soon!)</li></ul><h3>🚧 Common Gotchas</h3><ul><li>Recursive functions can <strong>crash</strong> the stack if they never stop calling themselves.</li><li>this behaves differently depending on whether you&#39;re in the global or a function context.</li><li>Hoisting happens during the <strong>creation phase</strong> of each context, not during execution.</li></ul><h3>🔜 What’s Next?</h3><p>Now that we’ve laid the foundation with Execution Contexts and the Call Stack, it’s time to zoom into how <strong>JavaScript keeps track of variables</strong> through different layers of function calls.</p><p>In the next post, we’ll dive into the <strong>Scope Chain</strong> — understanding how JavaScript resolves variables across nested functions and why some variables are accessible, and others are not.</p><p>Stay tuned — things are about to get even more interesting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2b712d4988b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ JS Unlocked #2 — Understanding Hoisting and the Temporal Dead Zone (TDZ)]]></title>
            <link>https://medium.com/@lobomalcon/js-unlocked-2-understanding-hoisting-and-the-temporal-dead-zone-tdz-0b531cbb6308?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b531cbb6308</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 08:12:22 GMT</pubDate>
            <atom:updated>2025-04-22T08:12:22.107Z</atom:updated>
            <content:encoded><![CDATA[<h3>🔍 JS Unlocked #2 — Understanding Hoisting and the Temporal Dead Zone (TDZ)</h3><blockquote><em>Ever wondered why some variables are accessible before they’re even declared… while others throw an error?</em></blockquote><p>Welcome back to <strong>JS Unlocked</strong> — your daily dive into the quirks and power of JavaScript. Today, we’re decoding <strong>hoisting</strong> and the mysterious <strong>temporal dead zone (TDZ)</strong> with visuals and simple analogies.</p><h3>🪄 What is Hoisting?</h3><p><strong>Hoisting</strong> is JavaScript’s behavior where variable and function <strong>declarations are moved to the top of their scope</strong> during the compilation phase — before code execution starts.</p><pre>console.log(greeting); // undefined<br>var greeting = &quot;Hello!&quot;;</pre><p>Here’s how JavaScript interprets it:</p><pre>var greeting;<br>console.log(greeting); // undefined<br>greeting = &quot;Hello!&quot;;</pre><h4>🔍 Visual: What hoisting looks like</h4><pre>Before Execution:</pre><pre>1. 🧠 JS scans for declarations<br>2. 🛗 Moves them to the top<br>3. 🧪 Runs your code</pre><pre>Result:<br>┌─────────────┐<br>| var greeting;       ✅ Declared (hoisted)<br>| console.log(greeting); // undefined<br>| greeting = &quot;Hello!&quot;;<br>└─────────────┘</pre><h3>🧠 Real-world Analogy for Hoisting</h3><blockquote><em>Imagine arriving at a conference where your name was already added to the attendance sheet — even if you haven’t walked in yet. You’re </em><strong><em>known</em></strong><em>, but no one knows your details yet.</em></blockquote><p>That’s var: the name is there, but it’s marked as <strong>undefined</strong> until you provide more information.</p><h3>📦 What Gets Hoisted?</h3><pre>Declaration Type    | Hoisted | Initialized | Access Before Declaration<br>--------------------|---------|-------------|----------------------------<br>var                 | Yes     | No          | Yes (returns undefined)<br>let                 | Yes     | No          | ❌ ReferenceError (TDZ)<br>const               | Yes     | No          | ❌ ReferenceError (TDZ)<br>function decl.      | Yes     | Yes         | Yes<br>arrow function      | As var  | No          | Depends on how it&#39;s declared</pre><h3>🚧 Enter the TDZ — Temporal Dead Zone</h3><p>When you use let or const, the variable <strong>is hoisted but not initialized</strong>. Trying to access it <strong>before the declaration line throws a ReferenceError</strong>. This inaccessible zone is called the <strong>Temporal Dead Zone</strong>.</p><pre>console.log(score); // ❌ ReferenceError<br>let score = 100;</pre><h4>🔍 Visual: TDZ in action</h4><pre>Block Scope:<br>{<br>   TDZ starts<br>   🔥 Access here = ReferenceError<br>   let score = 100; ✅ Declared and initialized<br>   console.log(score); // 100<br>}</pre><h3>🔄 Real-world Analogy for TDZ</h3><blockquote><em>You’re trying to enter a building, but the security system hasn’t been activated yet — even though the door exists. You </em><strong><em>can see the door</em></strong><em>, but it’s not functional until it’s been set up.</em></blockquote><p>That’s let and const inside the TDZ — <strong>they exist, but you can’t use them yet</strong>.</p><h3>🧩 Why Do Hoisting and TDZ Exist?</h3><p>Understanding <strong>why</strong> these behaviors exist helps us appreciate JavaScript’s design:</p><h4>🛗 Why Hoisting?</h4><p>JavaScript was designed to be <strong>developer-friendly</strong>, especially for beginners. Hoisting:</p><ul><li>Enables flexible coding styles</li><li>Allows functions to be used before they’re declared</li><li>Prevents crashes from using var too early by initializing it to undefined</li></ul><p>👉 It’s JavaScript being <strong>forgiving</strong>.</p><h4>🔐 Why the TDZ?</h4><p>With the introduction of let and const in ES6, JavaScript aimed to:</p><ul><li>Enforce cleaner, more predictable code</li><li>Prevent subtle bugs from early access</li><li>Discourage confusing hoisting behavior of var</li></ul><p>👉 TDZ is JavaScript being <strong>strict and safe</strong>.</p><h3>🆚 Hoisting vs TDZ — TL;DR</h3><pre>Concept     | Applies To         | Behavior<br>------------|--------------------|--------------------------------------<br>Hoisting    | All declarations   | Declarations are moved to the top<br>TDZ         | let &amp; const        | Access before declaration throws error</pre><h3>🏆 Best Practices</h3><ul><li>❌ Avoid var — it leads to confusing bugs</li><li>✅ Use const by default, let when reassignment is needed</li><li>🧼 Always declare variables at the top of your block</li><li>🔍 Understand hoisting &amp; TDZ to debug like a pro</li></ul><h3>🔗 What’s Next?</h3><p>In the next post, we’ll explore:</p><ul><li>How JavaScript <em>actually runs your code</em> step-by-step</li><li>What the <strong>Global Execution Context</strong> is, and why it matters</li><li>How the <strong>Call Stack</strong> works behind the scenes</li></ul><p>👉 Follow <strong>JS Unlocked</strong> to keep leveling up your JS knowledge, one post at a time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b531cbb6308" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[var, let, and const in JavaScript: Everything You Need to Know]]></title>
            <link>https://medium.com/@lobomalcon/var-let-and-const-in-javascript-everything-you-need-to-know-5fd97ad98856?source=rss-592b00df70fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fd97ad98856</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[Malcon Lobo]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 12:41:00 GMT</pubDate>
            <atom:updated>2025-04-21T12:41:00.169Z</atom:updated>
            <content:encoded><![CDATA[<p>When you’re starting with JavaScript — or even after years of writing it — understanding the difference between var, let, and const can make a surprising impact on the reliability and readability of your code.</p><p>In this post, we’ll break down:</p><ul><li>What each keyword does</li><li>How scoping and hoisting affect them</li><li>Common pitfalls to avoid</li><li>When to use what</li></ul><h3>1. var — The Old Guard</h3><p>Before ES6 (2015), var was the only way to declare variables in JavaScript. And it came with a few quirks:</p><h4>Key characteristics:</h4><ul><li><strong>Function scoped</strong>: Variables declared with var are accessible throughout the entire function they’re in—not just the block.</li><li><strong>Hoisting</strong>: Declarations (not initializations) are hoisted to the top of their scope.</li><li><strong>Can be redeclared</strong>: This can lead to unexpected behavior and bugs.</li></ul><h4>Example:</h4><pre>function demoVar() {<br>  console.log(a); // undefined, not ReferenceError<br>  var a = 10;<br>}</pre><p>This works because var a is hoisted to the top of the function. But the initialization (= 10) stays in place.</p><h4>Why avoid var?</h4><ul><li>Scoping confusion</li><li>Accidental redeclaration</li><li>Harder to reason about your code</li></ul><p>Unless you’re maintaining legacy code, there’s almost no reason to use var today.</p><h3>2. let — The Modern Replacement</h3><p>Introduced in ES6, let brought block scoping to JavaScript—finally matching how most other programming languages behave.</p><h4>Key characteristics:</h4><ul><li><strong>Block scoped</strong>: Only accessible within the {} block it’s declared in.</li><li><strong>Not hoisted (in the same way)</strong>: It <em>is</em> hoisted but exists in a <strong>Temporal Dead Zone (TDZ)</strong> until declared.</li><li><strong>Can be reassigned</strong>, but not redeclared in the same scope.</li></ul><h4>Example:</h4><pre>function demoLet() {<br>  console.log(x); // ReferenceError: Cannot access &#39;x&#39; before initialization<br>  let x = 5;<br>}</pre><p>This is where TDZ kicks in — let is hoisted, but accessing it before the line it’s declared on throws a ReferenceError.</p><h3>3. const — Constants (Kind of)</h3><p>Also introduced in ES6, const is very similar to let, but with one key difference: <strong>you can’t reassign it.</strong></p><h4>Key characteristics:</h4><ul><li><strong>Block scoped</strong>, just like let</li><li><strong>TDZ applies</strong> here too</li><li><strong>Cannot be reassigned</strong></li><li><strong>Doesn’t make objects or arrays immutable</strong> — only the reference is constant</li></ul><h4>Example:</h4><pre>const person = { name: &quot;Alex&quot; };<br>person.name = &quot;Sam&quot;; // Works<br><br>person = { name: &quot;Taylor&quot; }; // TypeError</pre><p>You can mutate the contents of an object declared with const, but you can’t reassign it to a new one.</p><h3>4. Best Practices</h3><p>Here’s how most modern JavaScript developers handle declarations:</p><ul><li><strong>Default to </strong><strong>const</strong></li><li>Use let only when you need to reassign a variable</li><li><strong>Never use </strong><strong>var</strong> (unless you&#39;re forced to)</li></ul><p>This mindset enforces immutability by default and avoids unintended bugs.</p><h3>5. Quick Comparison Table</h3><pre>| Feature         | var              |  let          | const          |<br>|-----------------|------------------|---------------|----------------|<br>| Scope           | Function         | Block         | Block          |<br>| Hoisted         | Yes (undefined)  | Yes (TDZ)     | Yes (TDZ)      |<br>| Reassignable    | Yes              | Yes           | No             |<br>| Redeclarable    | Yes              | No            | No             |<br>| Use Case        | Legacy only      | Mutable       | Immutable ref  |</pre><h3>6. Final Thoughts</h3><p>JavaScript’s quirks are part of what makes it powerful — but also error-prone if misunderstood. By fully grasping how var, let, and const work, you’ll write cleaner, safer code that behaves the way you expect.</p><p><strong>Next up:</strong> I’ll be diving into JavaScript hoisting and the temporal dead zone in detail. Follow me here or on <a href="https://www.linkedin.com/in/malcon-lobo-384010137/">LinkedIn</a> to catch the next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fd97ad98856" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>