<?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>DEV Community: Yashwanth Reddy Boreddy</title>
    <description>The latest articles on DEV Community by Yashwanth Reddy Boreddy (@byashwanthreddy9036ux).</description>
    <link>https://dev.to/byashwanthreddy9036ux</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%2F3754961%2F0b156a1b-c28a-4812-befe-114339ecb76a.png</url>
      <title>DEV Community: Yashwanth Reddy Boreddy</title>
      <link>https://dev.to/byashwanthreddy9036ux</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/byashwanthreddy9036ux"/>
    <language>en</language>
    <item>
      <title>The Day "this" Betrayed Me in JavaScript</title>
      <dc:creator>Yashwanth Reddy Boreddy</dc:creator>
      <pubDate>Tue, 14 Apr 2026 17:11:46 +0000</pubDate>
      <link>https://dev.to/byashwanthreddy9036ux/the-day-this-betrayed-me-in-javascript-15n9</link>
      <guid>https://dev.to/byashwanthreddy9036ux/the-day-this-betrayed-me-in-javascript-15n9</guid>
      <description>&lt;p&gt;This is one of those things that looks small… but quietly breaks everything you thought was working.&lt;/p&gt;

&lt;p&gt;Not gonna lie, this wasn’t an instant “I get it” moment. It was confusion first, then frustration, and then clarity. Somewhere in between, something about how I see JavaScript changed.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Where This Even Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was building a CLI-based task manager.&lt;/p&gt;

&lt;p&gt;Nothing crazy or complex. Server side was fine. On the client side, I decided to structure things properly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A class&lt;/li&gt;
&lt;li&gt;Methods&lt;/li&gt;
&lt;li&gt;API calls&lt;/li&gt;
&lt;li&gt;A menu-driven system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything looked clean. Everything felt right.&lt;br&gt;
Until it didn’t.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;The Problem That Made No Sense&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had something like 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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;2&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;getTaskByPriority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;3&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;createTask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks completely normal.&lt;/p&gt;

&lt;p&gt;Then I called it:&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="k"&gt;await&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;OPTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And suddenly, &lt;code&gt;this&lt;/code&gt; was &lt;code&gt;undefined&lt;/code&gt;… or worse, it pointed somewhere random.&lt;/p&gt;

&lt;p&gt;That’s where it got frustrating. This was inside a class, so why was it behaving like it wasn’t?&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Where My Thinking Went Wrong&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started questioning everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Isn’t &lt;code&gt;this&lt;/code&gt; supposed to refer to the object?&lt;/li&gt;
&lt;li&gt;Is this some class related issue?&lt;/li&gt;
&lt;li&gt;Is JavaScript being weird because it’s loosely typed?&lt;/li&gt;
&lt;li&gt;Why do I have to tell it what &lt;code&gt;this&lt;/code&gt; is?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the worst part is, JavaScript doesn’t fail loudly here. It just quietly does the wrong thing.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;The Real Problem (The Thing I Missed)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The issue wasn’t classes, OOP or Syntax.&lt;/p&gt;

&lt;p&gt;It was this one rule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In JavaScript, &lt;code&gt;this&lt;/code&gt; depends on how a function is called not where it is written.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s it. That’s the whole game.&lt;br&gt;
That single idea explains everything.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;What Was Actually Happening&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When I wrote this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1: this.getAllTasks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I thought I was “storing a method”. But I wasn’t. I was extracting a function… a raw function reference, detached from the object.&lt;/p&gt;

&lt;p&gt;Later, when I did:&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OPTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That function gets called like a normal function, not like:&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So JavaScript had no context for &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In strict mode, it becomes &lt;code&gt;undefined&lt;/code&gt;. Otherwise, it falls back to the global object. Either way, it breaks anything that depends on instance properties like:&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&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;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/tasks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;The Fix That Felt Weird at First&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then came 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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;2&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;getTaskByPriority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;3&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;createTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first, it felt unnecessary. Why bind something that already belongs to the class?&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;.bind(this)&lt;/code&gt; creates a new function and permanently locks it's &lt;code&gt;this&lt;/code&gt;to the current instance. No matter where that function is called later, it won’t lose it's context.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What .bind(this) Really Means&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;bind&lt;/code&gt;:&lt;br&gt;
The function forgets who owns it.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;bind&lt;/code&gt;:&lt;br&gt;
The function carries it's owner everywhere.&lt;/p&gt;

&lt;p&gt;That’s it. That’s the difference.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;The Part Where It Actually Matters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where everything clicked:&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="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;start&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;OPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;2&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;getTaskByPriority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;3&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;createTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;4&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;updateTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="mi"&gt;5&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;deleteTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getUserChoice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;OPTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;choice&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid choice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;await&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;OPTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same structure, same logic but now it works perfectly.&lt;br&gt;
The only difference is that the context is no longer lost.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Why JavaScript Works Like This&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This started making more sense when I looked at how JavaScript is designed.&lt;/p&gt;

&lt;p&gt;It’s function-first and highly flexible. Functions are just values you can pass them around freely, store them, and call them anywhere.&lt;/p&gt;

&lt;p&gt;But they don’t carry context automatically.&lt;/p&gt;

&lt;p&gt;Other languages tie methods to objects at definition time. JavaScript doesn’t. Here, context is decided at call time.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;The Connection I Noticed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This reminded me of something else 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="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first, it feels inconsistent. But then the pattern is the same… JavaScript gives flexibility first and lets you opt into strictness&lt;/p&gt;

&lt;p&gt;Same idea here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions are free by default&lt;/li&gt;
&lt;li&gt;Context is optional&lt;/li&gt;
&lt;li&gt;You decide when to lock it (&lt;code&gt;bind&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Another Way to Fix It (That Felt More Natural)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of &lt;code&gt;bind&lt;/code&gt;, I also tried 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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&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="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTaskByPriority&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTask&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This worked too. Because arrow functions don’t have their own &lt;code&gt;this&lt;/code&gt;. They inherit it from where they are defined.&lt;/p&gt;

&lt;p&gt;I had actually used this pattern before in event listeners:&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;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&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;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At that time, I wasn’t thinking about &lt;code&gt;this&lt;/code&gt;. Now it makes sense why it worked.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;The Bigger Realization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This wasn’t really about &lt;code&gt;.bind()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It was about understanding how JavaScript thinks.&lt;/p&gt;

&lt;p&gt;I assumed methods stay attached to objects. But in JavaScript, functions don’t belong to anything unless you explicitly bind them.&lt;/p&gt;

&lt;p&gt;That was the mental shift.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;One Subtle Thing I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.bind(this)&lt;/code&gt; does not modify the original function.&lt;/p&gt;

&lt;p&gt;It creates a new one.&lt;/p&gt;

&lt;p&gt;So 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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getAllTasks&lt;/span&gt; &lt;span class="o"&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;getAllTasks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are different functions.&lt;/p&gt;

&lt;p&gt;This matters if you ever compare functions or try to remove event listeners.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Final Thought&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This didn’t make me feel smart. It made me feel confused, then frustrated, and finally clear. &lt;br&gt;
And honestly, that’s progress.&lt;/p&gt;

&lt;p&gt;If you’re stuck on &lt;code&gt;this&lt;/code&gt; and &lt;code&gt;.bind()&lt;/code&gt;, you’re not alone. It doesn’t click immediately, but once it does… you stop fighting JavaScript and start understanding it.&lt;/p&gt;




&lt;p&gt;I’m still new to this, but this one definitely changed how I look at the language.&lt;br&gt;
And yeah, that’s another shell cracked.&lt;/p&gt;

</description>
      <category>learning</category>
      <category>javascript</category>
      <category>oop</category>
      <category>programming</category>
    </item>
    <item>
      <title>When Patterns Stop Being About Patterns: My Battle With the Spiral (Snail) Matrix</title>
      <dc:creator>Yashwanth Reddy Boreddy</dc:creator>
      <pubDate>Thu, 05 Feb 2026 16:06:12 +0000</pubDate>
      <link>https://dev.to/byashwanthreddy9036ux/when-patterns-stop-being-about-patterns-my-battle-with-the-spiral-snail-matrix-4p3j</link>
      <guid>https://dev.to/byashwanthreddy9036ux/when-patterns-stop-being-about-patterns-my-battle-with-the-spiral-snail-matrix-4p3j</guid>
      <description>&lt;h2&gt;
  
  
  This is my breakthrough journey, how I finally cracked one of the most head breaking pattern problems I’ve ever faced.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 2 3
8 9 4
7 6 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This thing looks innocent.&lt;br&gt;
It is not.&lt;/p&gt;

&lt;p&gt;I struggled with this for more than a day. Literally stuck.&lt;br&gt;
Out of an assignment of 85 pattern questions, this was the last one, it felt intentionally designed to break us so we couldn’t complete the set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where My Brain Got Stuck&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After solving 80+ pattern problems using loops in JavaScript, my brain had been trained (or ruined) to see everything as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;math based&lt;/li&gt;
&lt;li&gt;loop based&lt;/li&gt;
&lt;li&gt;i and j manipulation&lt;/li&gt;
&lt;li&gt;stars, numbers, symmetry&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Triangles.&lt;br&gt;
Inverted triangles.&lt;br&gt;
Pyramids.&lt;br&gt;
Hourglasses.&lt;br&gt;
Butterflies.&lt;br&gt;
Hollow patterns.&lt;br&gt;
If it had a name, I probably printed it.&lt;/p&gt;

&lt;p&gt;So when this came up, my brain automatically tried to force a mathematical formula out of it.&lt;/p&gt;

&lt;p&gt;I kept asking questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How do I manipulate i and j?&lt;/li&gt;
&lt;li&gt;Can I tweak loop conditions?&lt;/li&gt;
&lt;li&gt;Is there some magic equation behind this?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that was the mistake.&lt;/p&gt;

&lt;p&gt;I wasn’t looking at it as rows and columns.&lt;br&gt;
I wasn’t seeing it as a matrix.&lt;br&gt;
I was trying to treat it like a normal pattern problem and it just refused to cooperate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Mental Shift That Changed Everything&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The breakthrough didn’t come from more loops.&lt;br&gt;
It came from changing how I looked at the problem.&lt;/p&gt;

&lt;p&gt;This was not a pattern problem.&lt;br&gt;
This was a matrix traversal problem disguised as a pattern.&lt;/p&gt;

&lt;p&gt;Once I started treating the output as a 2D grid, things slowly started making sense.&lt;/p&gt;

&lt;p&gt;Even then, I won’t lie... the brainstorming continued.&lt;br&gt;
I still couldn’t see the full solution immediately.&lt;br&gt;
But at least now, I had a direction.&lt;/p&gt;

&lt;p&gt;And that was something I didn’t even have before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thinking in Boundaries, Not Formulas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of trying to calculate positions, the idea was simple:&lt;/p&gt;

&lt;p&gt;Fill the matrix layer by layer&lt;/p&gt;

&lt;p&gt;Move in four directions&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;left → right&lt;/li&gt;
&lt;li&gt;top → bottom&lt;/li&gt;
&lt;li&gt;right → left&lt;/li&gt;
&lt;li&gt;bottom → top&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Shrink the boundaries after each pass&lt;/p&gt;

&lt;p&gt;This is where top, bottom, left, and right come in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Code That Finally Worked&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = 3;

let matrix = Array.from({ length: n }, () =&amp;gt; Array(n).fill(0));

//let matrix = [
//    [1, 2, 3],
//    [4, 5, 6],
//    [7, 8, 9]
//];

let num = 1;

// Boundaries
let top = 0, bottom = n - 1;
let left = 0, right = n - 1;

while (num &amp;lt;= n * n) {

    // left → right
    for (let i = left; i &amp;lt;= right; i++) {
        matrix[top][i] = num++;
    }
    top++;

    // top → bottom
    for (let i = top; i &amp;lt;= bottom; i++) {
        matrix[i][right] = num++;
    }
    right--;

    // right → left
    for (let i = right; i &amp;gt;= left; i--) {
        matrix[bottom][i] = num++;
    }
    bottom--;

    // bottom → top
    for (let i = bottom; i &amp;gt;= top; i--) {
        matrix[i][left] = num++;
    }
    left++;
}

// Print result
for (let row of matrix) {
    console.log(row.join(' '));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What’s Actually Happening Here (Plain English)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;num keeps increasing from 1 to n * n&lt;/p&gt;

&lt;p&gt;top, bottom, left, right define the current layer&lt;/p&gt;

&lt;p&gt;Each loop fills one side of the spiral&lt;/p&gt;

&lt;p&gt;After finishing a side, we move the boundary inward&lt;/p&gt;

&lt;p&gt;The while loop ensures we stop exactly when the matrix is full&lt;/p&gt;

&lt;p&gt;No formulas.&lt;br&gt;
No pattern tricks.&lt;br&gt;
Just controlled movement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;About That Array.from() Thing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first, I directly wrote the matrix values manually.&lt;/p&gt;

&lt;p&gt;Later, I switched to something like this:&lt;/p&gt;

&lt;p&gt;let matrix = Array.from({ length: n }, () =&amp;gt; Array(n).fill(0));&lt;/p&gt;

&lt;p&gt;No BS,&lt;br&gt;
I was using it without fully understanding it at first and I still don't.&lt;/p&gt;

&lt;p&gt;But here’s what it does:&lt;/p&gt;

&lt;p&gt;Creates an array with n rows&lt;/p&gt;

&lt;p&gt;Each row is a new array of size n&lt;/p&gt;

&lt;p&gt;Fills everything with 0&lt;/p&gt;

&lt;p&gt;Prevents reference issues (which is important)&lt;/p&gt;

&lt;p&gt;This allows the same logic to work for any size, not just 3 × 3.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Real Lesson (Not the Code)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This problem taught me something bigger than spiral matrices:&lt;/p&gt;

&lt;p&gt;Sometimes the problem isn’t hard&lt;br&gt;
your mental model is wrong.&lt;/p&gt;

&lt;p&gt;I wasn’t failing because I didn’t know loops.&lt;br&gt;
I was failing because I was trying to force the problem into a shape it wasn’t.&lt;/p&gt;

&lt;p&gt;Once I stopped treating it as a pattern and started treating it as a matrix traversal, everything clicked.&lt;/p&gt;

&lt;p&gt;And yeah I needed guidance.&lt;br&gt;
But more importantly, I needed a shift in perspective.&lt;/p&gt;

&lt;p&gt;That’s the shell I finally cracked &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ending this before I over explain&lt;/strong&gt;&lt;br&gt;
I’m still new to this.&lt;/p&gt;

&lt;p&gt;This question didn’t make me feel smart it made me feel stuck, then relieved.&lt;/p&gt;

&lt;p&gt;If you’re struggling with this pattern, you’re not alone. It’s confusing until it isn’t.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
