<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Samaresh Das</title>
    <description>The latest articles on Forem by Samaresh Das (@samareshdas).</description>
    <link>https://forem.com/samareshdas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F861109%2F7d96ea45-4290-422f-9747-e480e8000f2c.jpg</url>
      <title>Forem: Samaresh Das</title>
      <link>https://forem.com/samareshdas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/samareshdas"/>
    <language>en</language>
    <item>
      <title>Stop memorizing JS — think in execution context</title>
      <dc:creator>Samaresh Das</dc:creator>
      <pubDate>Thu, 23 Apr 2026 09:00:55 +0000</pubDate>
      <link>https://forem.com/samareshdas/stop-memorizing-js-think-in-execution-context-2ne4</link>
      <guid>https://forem.com/samareshdas/stop-memorizing-js-think-in-execution-context-2ne4</guid>
      <description>&lt;p&gt;Forget remembering JavaScript syntax; it's a crutch.&lt;/p&gt;

&lt;p&gt;What if I told you that the key to truly &lt;em&gt;understanding&lt;/em&gt; JavaScript isn't memorizing endless functions and methods, but grasping how the code actually runs? This article is about shifting your focus from rote learning to thinking about JavaScript's execution context.&lt;/p&gt;

&lt;p&gt;Every time your JavaScript code runs, the engine creates an "execution context." Think of it as a mini-environment where your code gets evaluated. There are two main types: the Global Execution Context (the default one for your entire script) and the Function Execution Context (created each time a function is called).&lt;/p&gt;

&lt;p&gt;Within each context, two crucial things happen: the creation phase and the execution phase. During creation, the engine sets up the &lt;code&gt;Variable Environment&lt;/code&gt; (where &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;, and function declarations are stored) and the &lt;code&gt;this&lt;/code&gt; binding. It also creates the &lt;code&gt;scope chain&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then comes the execution phase, where the actual JavaScript code is run line by line. This is where &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declarations are put into a "temporal dead zone" until their declaration is reached, while &lt;code&gt;var&lt;/code&gt; variables are initialized with &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's look at a simple example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 10&lt;/span&gt;

&lt;span class="c1"&gt;// sayHello(); // This would throw an error&lt;/span&gt;
&lt;span class="c1"&gt;// let sayHello = () =&amp;gt; {&lt;/span&gt;
&lt;span class="c1"&gt;//   console.log("Hello!");&lt;/span&gt;
&lt;span class="c1"&gt;// };&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first &lt;code&gt;console.log(a)&lt;/code&gt; outputs &lt;code&gt;undefined&lt;/code&gt; because &lt;code&gt;var a&lt;/code&gt; is hoisted to the top of its scope and initialized with &lt;code&gt;undefined&lt;/code&gt; during the creation phase, &lt;em&gt;before&lt;/em&gt; the execution phase reaches &lt;code&gt;var a = 10;&lt;/code&gt;. If &lt;code&gt;a&lt;/code&gt; were declared with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;, the first &lt;code&gt;console.log&lt;/code&gt; would actually throw a &lt;code&gt;ReferenceError&lt;/code&gt; because of the temporal dead zone.&lt;/p&gt;

&lt;p&gt;Understanding execution context helps untangle confusing behavior, especially with asynchronous operations and closures. It's the "why" behind what your code is doing.&lt;/p&gt;

&lt;p&gt;For me, this mindset shift was a game-changer. It's what allows me to build complex websites and apps as a freelancer. If you're ever looking for someone to build your next web project, you can check out my portfolio here: &lt;a href="https://hire-sam.vercel.app/" rel="noopener noreferrer"&gt;https://hire-sam.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The real superpower in JavaScript isn't memorization, it's understanding the runtime.&lt;/p&gt;

&lt;p&gt;Follow for more dev content&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>JS concepts I understood only after building real things</title>
      <dc:creator>Samaresh Das</dc:creator>
      <pubDate>Wed, 22 Apr 2026 09:00:53 +0000</pubDate>
      <link>https://forem.com/samareshdas/js-concepts-i-understood-only-after-building-real-things-a6f</link>
      <guid>https://forem.com/samareshdas/js-concepts-i-understood-only-after-building-real-things-a6f</guid>
      <description>&lt;p&gt;The tutorials never told you the &lt;em&gt;real&lt;/em&gt; story about these JavaScript concepts.&lt;/p&gt;

&lt;p&gt;We've all been there, right? You've read the docs, watched countless videos, and felt like you &lt;em&gt;got&lt;/em&gt; a JavaScript concept. Then, you try to apply it to a real-world project, and suddenly, it's like learning it for the first time all over again. That's been my journey as a freelancer building websites, and these are the JS concepts that really clicked only after getting my hands dirty with actual client work.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; Keyword: The Elusive Chameleon
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; keyword is probably the biggest culprit. In tutorials, it often seems straightforward, tied neatly to the object it's called upon. But in the wild, &lt;code&gt;this&lt;/code&gt; is a shape-shifter. Its value depends &lt;em&gt;entirely&lt;/em&gt; on how a function is invoked. Strict mode, arrow functions, &lt;code&gt;bind&lt;/code&gt;, &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; – these all change its behavior in ways that will make your head spin until you've debugged a few messy callbacks or event handlers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Tutorial version: "See? it's the object!"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MyObject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello from &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Hello from MyObject"&lt;/span&gt;

&lt;span class="c1"&gt;// Real-world chaos:&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sayHi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// 'this' here is often window or undefined in strict mode!&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hi, I'm &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sam&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Might not work as expected!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Asynchronous JavaScript: Beyond &lt;code&gt;async/await&lt;/code&gt; Syntax
&lt;/h3&gt;

&lt;p&gt;Sure, &lt;code&gt;async/await&lt;/code&gt; makes asynchronous code &lt;em&gt;look&lt;/em&gt; synchronous, which is a huge win. But understanding &lt;em&gt;what's happening under the hood&lt;/em&gt; with the event loop, the microtask queue, and the macrotask queue is crucial for performance optimization and preventing dreaded race conditions. It’s not just about writing clean code; it's about writing &lt;em&gt;predictable&lt;/em&gt; code.&lt;/p&gt;

&lt;p&gt;Think about handling multiple API requests where the order matters, or dealing with user input that triggers background operations. Without a grasp of the event loop, debugging those situations feels like trying to catch smoke.&lt;/p&gt;

&lt;h3&gt;
  
  
  Closures: More Than Just Scope Holding
&lt;/h3&gt;

&lt;p&gt;Closures are often explained as functions remembering their parent scope. That's technically true, but the real power and utility become apparent when you build things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Data encapsulation:&lt;/strong&gt; Creating private variables that can't be directly accessed or modified from outside.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Currying and partial application:&lt;/strong&gt; Creating specialized versions of functions.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Event handlers that maintain state:&lt;/strong&gt; Imagine clicking a button multiple times and having it remember how many times it's been clicked without needing a global variable.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This variable is "closed over" by the returned function&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counter1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;counter1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nf"&gt;counter1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counter2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;counter2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 1 (independent count)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Building real features, whether for a small business website or a complex web application, forces you to confront these concepts not as academic exercises, but as fundamental tools for problem-solving. If you’re looking for someone to help bring your web projects to life, you can check out what I do at &lt;a href="https://hire-sam.vercel.app/" rel="noopener noreferrer"&gt;https://hire-sam.vercel.app/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The takeaway? Don't just learn the syntax; understand the &lt;em&gt;behavior&lt;/em&gt; and the &lt;em&gt;implications&lt;/em&gt; in a live application. That's where true mastery lies.&lt;/p&gt;

&lt;p&gt;Follow for more dev content.&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #webdevelopment #programming #freelancer
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>freelancer</category>
    </item>
    <item>
      <title>Why interviews expose your JS gaps</title>
      <dc:creator>Samaresh Das</dc:creator>
      <pubDate>Tue, 21 Apr 2026 09:00:59 +0000</pubDate>
      <link>https://forem.com/samareshdas/why-interviews-expose-your-js-gaps-1h35</link>
      <guid>https://forem.com/samareshdas/why-interviews-expose-your-js-gaps-1h35</guid>
      <description>&lt;p&gt;Interviews are not trying to trick you; they're just a highly effective JavaScript lie detector.&lt;/p&gt;

&lt;p&gt;You might be crushing it daily, shipping features, and building fantastic applications with all the modern frameworks. But then an interview question about &lt;code&gt;this&lt;/code&gt; context or closures drops, and suddenly you feel like you've never written a line of JavaScript in your life. This isn't about failing; it's about exposing the difference between "getting it done" and "understanding what's happening."&lt;/p&gt;

&lt;p&gt;The reason these "gap-exposing" questions pop up is because daily development often abstracts away the core mechanics. We rely on frameworks and libraries that handle much of the underlying complexity. While efficient, this can lead to a shallower understanding of the language's foundational principles.&lt;/p&gt;

&lt;p&gt;Let's take &lt;code&gt;this&lt;/code&gt; for example. You use it all the time in React components or class methods, but what happens when you pull a method out of its object context?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hey, I'm &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// What does this print?&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// And this?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a daily dev scenario, you might only ever call &lt;code&gt;user.greet()&lt;/code&gt;. But an interviewer wants to see if you understand how &lt;code&gt;this&lt;/code&gt; is dynamically bound based on &lt;em&gt;how&lt;/em&gt; a function is called, not where it's defined.&lt;/p&gt;

&lt;p&gt;Another classic is closures. We use them constantly, often without explicitly thinking about them. Think about event listeners, higher-order functions like &lt;code&gt;map&lt;/code&gt; or &lt;code&gt;filter&lt;/code&gt;, or even just functions that return other functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 'count' is captured by the inner function&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding closures helps you grasp concepts like private variables, module patterns, and how asynchronous operations retain their context. It’s fundamental.&lt;/p&gt;

&lt;p&gt;The takeaway is simple: interviews often probe the bedrock of JavaScript because a solid foundation makes you adaptable. It means you can debug tricky issues, pick up new frameworks faster, and write more robust code, even when the abstractions fail or you need to dive deep. It’s not about memorizing trivia, but understanding the "why" behind the magic. ✨&lt;/p&gt;

&lt;p&gt;Building websites for clients as a freelancer, I've noticed a pattern: the deeper your JS fundamentals, the smoother the sailing on tricky projects. If you need a hand with a web project, you can always check out my work here: &lt;a href="https://hire-sam.vercel.app/" rel="noopener noreferrer"&gt;https://hire-sam.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Share this with your dev friends who dread JS interviews!&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #webdev #frontend #career #interview
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>career</category>
    </item>
    <item>
      <title>Using AI to understand JS, not copy code</title>
      <dc:creator>Samaresh Das</dc:creator>
      <pubDate>Mon, 20 Apr 2026 11:25:46 +0000</pubDate>
      <link>https://forem.com/samareshdas/using-ai-to-understand-js-not-copy-code-2hb8</link>
      <guid>https://forem.com/samareshdas/using-ai-to-understand-js-not-copy-code-2hb8</guid>
      <description>&lt;p&gt;Blindly copying AI-generated code is the fastest way to &lt;em&gt;not&lt;/em&gt; learn JavaScript.&lt;/p&gt;

&lt;p&gt;We all love the convenience of AI tools like ChatGPT or GitHub Copilot for a quick snippet. But relying on them to just churn out solutions can seriously stunt your growth as a developer. Instead of using AI as a crutch, let's turn it into a super-powered tutor for genuinely understanding JavaScript.&lt;/p&gt;

&lt;p&gt;The real magic happens when you ask "why" and "how," not just "what." Think of AI as your personal rubber duck, but one that can actually talk back and provide analogies. It's about shifting from 'fix this for me' to 'explain this to me.'&lt;/p&gt;

&lt;p&gt;Let's say you're wrestling with the infamous &lt;code&gt;this&lt;/code&gt; keyword in JavaScript. Instead of asking for code that &lt;em&gt;uses&lt;/em&gt; &lt;code&gt;this&lt;/code&gt;, ask the AI to &lt;em&gt;explain&lt;/em&gt; its behavior in different contexts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Global context&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Function context&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Method context&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sam&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could prompt: "Explain the &lt;code&gt;this&lt;/code&gt; keyword in JavaScript for global scope, a regular function, and a method on an object. Provide a brief code example for each scenario." The AI's explanation will help clarify &lt;em&gt;why&lt;/em&gt; &lt;code&gt;this&lt;/code&gt; behaves the way it does, rather than just seeing it in action.&lt;/p&gt;

&lt;p&gt;Another common scenario: debugging. Rather than pasting an error and asking the AI to fix it, paste your broken code along with the error message and ask: "I'm getting &lt;code&gt;TypeError: Cannot read properties of undefined (reading 'name')&lt;/code&gt; with this code. Can you explain &lt;em&gt;why&lt;/em&gt; this error is happening and what it usually indicates in JavaScript?"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;details&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// name: 'Alice' - intentionally missing&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// TypeError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This forces the AI to break down the error message and explain the underlying concept (e.g., trying to access a property on an undefined object), which is far more valuable for your long-term learning.&lt;/p&gt;

&lt;p&gt;Here are a few ways to leverage AI for understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Ask for analogies&lt;/strong&gt;: "Explain closures in JavaScript using a real-world analogy."&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Request alternative solutions&lt;/strong&gt;: "I wrote this &lt;code&gt;for&lt;/code&gt; loop. Can you show me a more modern or functional way to achieve the same result using array methods, and explain the benefits?"&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Deconstruct complex code&lt;/strong&gt;: Paste a library example you don't fully grasp and ask the AI to explain each part step-by-step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ultimately, understanding the 'why' behind the code helps me build much better, more maintainable websites for my clients. It's a principle I apply in all my freelance projects. If you're ever looking for a dev who cares about the fundamentals, you can find more about what I do here: &lt;a href="https://hire-sam.vercel.app/" rel="noopener noreferrer"&gt;https://hire-sam.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Think of AI not as your code monkey, but as your highly knowledgeable (and sometimes a bit quirky) study buddy 🤔. Use it to expand your brain, not just your codebase.&lt;/p&gt;

&lt;p&gt;Save this if useful!&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #ai #webdevelopment #codingtips #devcommunity
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>ai</category>
      <category>webdev</category>
      <category>codingtips</category>
    </item>
    <item>
      <title>Why closures finally clicked for me after 2 years</title>
      <dc:creator>Samaresh Das</dc:creator>
      <pubDate>Sun, 19 Apr 2026 20:12:54 +0000</pubDate>
      <link>https://forem.com/samareshdas/why-closures-finally-clicked-for-me-after-2-years-3i2g</link>
      <guid>https://forem.com/samareshdas/why-closures-finally-clicked-for-me-after-2-years-3i2g</guid>
      <description>&lt;p&gt;Closures aren't magic, but for two years, I genuinely thought they were dark sorcery.&lt;/p&gt;

&lt;p&gt;If you've ever felt utterly baffled by how a function remembers variables from its parent scope long after the parent has returned, you're definitely not alone. This is about that "aha!" moment when JavaScript closures stopped being an abstract concept and started making actual sense to me.&lt;/p&gt;

&lt;p&gt;My journey was a mix of copying code, using frameworks that subtly abstracted them, and nodding vaguely when someone mentioned "lexical environment." I knew they existed, but truly understanding their power felt like trying to catch smoke. I pictured some kind of JavaScript ghost holding onto variables. 😂&lt;/p&gt;

&lt;p&gt;The core idea, once it finally clicked, is surprisingly simple: A closure is when a function "remembers" its lexical environment even when that function is executed outside its original scope. Think of it as a function carrying a little backpack of variables from where it was created, a memory of its birthplace. This "lexical environment" just means the variables and functions that were available where the function was declared.&lt;/p&gt;

&lt;p&gt;Let's look at a classic example that finally made it click for me – a simple counter function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This variable is part of createCounter's lexical environment&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This inner function forms a closure&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how &lt;code&gt;myCounter&lt;/code&gt; continues to increment &lt;code&gt;count&lt;/code&gt;, even though &lt;code&gt;createCounter()&lt;/code&gt; has already finished executing and its execution context has technically "popped off the stack." The inner function returned by &lt;code&gt;createCounter&lt;/code&gt; "closed over" the &lt;code&gt;count&lt;/code&gt; variable. It keeps a persistent reference to it, allowing its value to be maintained across multiple calls.&lt;/p&gt;

&lt;p&gt;Why is this seemingly abstract concept incredibly useful in web development?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Data Privacy/Encapsulation:&lt;/strong&gt; You can create "private" variables that only the inner function can access, protecting them from external modification and preventing global scope pollution.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Factory Functions:&lt;/strong&gt; Closures let you generate custom functions with pre-configured settings, making your code more flexible and reusable. For instance, a function that creates different types of validators.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Stateful Functions &amp;amp; Event Handlers:&lt;/strong&gt; They're crucial for remembering context for callbacks in asynchronous operations or when attaching event listeners. Each event handler can have its own persistent data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another quick example using a "factory" for event listeners – a common pattern (though frameworks often abstract this):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createButtonClickHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buttonId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This inner function closes over 'buttonId'&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Button &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;buttonId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; was clicked!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// We can now perform actions specific to this buttonId&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Imagine having buttons with IDs 'saveBtn', 'deleteBtn'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;saveHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createButtonClickHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saveBtn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deleteHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createButtonClickHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deleteBtn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// In a real app, you'd attach these to actual DOM elements:&lt;/span&gt;
&lt;span class="c1"&gt;// document.getElementById('saveBtn').addEventListener('click', saveHandler);&lt;/span&gt;

&lt;span class="c1"&gt;// Simulating clicks for demonstration:&lt;/span&gt;
&lt;span class="nf"&gt;saveHandler&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;   &lt;span class="c1"&gt;// Output: "Button saveBtn was clicked!"&lt;/span&gt;
&lt;span class="nf"&gt;deleteHandler&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Button deleteBtn was clicked!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each handler function remembers &lt;em&gt;its own&lt;/em&gt; &lt;code&gt;buttonId&lt;/code&gt; from when it was created. That's the closure doing its job, providing isolated state for each callback.&lt;/p&gt;

&lt;p&gt;The single biggest takeaway is that functions don't just execute code; they also &lt;em&gt;remember&lt;/em&gt; the environment in which they were born. This memory is what a closure is all about.&lt;/p&gt;

&lt;p&gt;Understanding these core JavaScript concepts like closures isn't just academic; it directly translates into writing more robust, maintainable, and efficient code for the websites I build. It's especially useful when architecting complex client-side applications or custom utility functions for freelance projects. If you need a hand bringing a web project to life, you can learn more about my work here: &lt;a href="https://hire-sam.vercel.app/" rel="noopener noreferrer"&gt;https://hire-sam.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save this if useful! 💡&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #webdev #frontend #programming
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
