<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Abhijit Mone]]></title><description><![CDATA[Techno geek.]]></description><link>https://blogs.abhijitmone.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 21:43:12 GMT</lastBuildDate><atom:link href="https://blogs.abhijitmone.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Kafka Explained Like you're 5]]></title><description><![CDATA[Imagine You're are at a massive train station. Thousands of people are constantly making announcements - like arrivals, departures, delays, lost luggage, platform changes, gate changes and more.Everyo]]></description><link>https://blogs.abhijitmone.com/kafka-explained-like-you-re-5</link><guid isPermaLink="true">https://blogs.abhijitmone.com/kafka-explained-like-you-re-5</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[System Design]]></category><category><![CDATA[kafka]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Mon, 16 Mar 2026 19:05:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/fb83cb8a-9635-4653-881e-1afea4365442.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine You're are at a massive train station. Thousands of people are constantly making announcements - like arrivals, departures, delays, lost luggage, platform changes, gate changes and more.Everyone is talking at once. How do you make sure the right message will reach the right person/people, <strong>without loosing a single one</strong> ?<br />That's exactly the problem Apache Kafka was built to solve. And once you get the analogy, everything else clicks.  </p>
<p><strong>What we'll cover</strong></p>
<p>The problem Kafka solves → message streams → topics → producers → partitions → consumer groups → how Kafka stays fast and safe. All with zero jargon.</p>
<h2>What problem does the Kafka solve?</h2>
<p>Modern apps are not simple request-response machines anymore. Think about what happens when you order something on Swiggy:</p>
<ul>
<li><p>The order service records your order</p>
</li>
<li><p>The payment service charges your card</p>
</li>
<li><p>The restaurant gets notified</p>
</li>
<li><p>The delivery partner app updates</p>
</li>
<li><p>Your notification system pings you</p>
</li>
</ul>
<p>All of this happens <strong>simultaneously</strong>, triggered by a single button tap. How do you connect all these services without creating a tangled mess where every service talks directly to every other service?</p>
<p><em>Without Kafka, it's like every person in a stadium trying to whisper their message directly to everyone else. Chaos. With Kafka, there's one giant PA system that everyone can broadcast to — and anyone who cares can listen.</em></p>
<p>The old way was direct service-to-service calls. If the notification service is down, the order can't complete. Services become tightly coupled — break one, break all. <strong>Kafka decouples them entirely.</strong></p>
<h2><strong>What Is a Message Stream?</strong></h2>
<p>Think of a river. Water flows continuously — it doesn't stop because you aren't looking at it. A <strong>message stream</strong> is exactly that: a continuous, never-ending flow of events.</p>
<p>Every click, every purchase, every sensor reading, every login — these are all <em>events</em>. They happen constantly, in real time. A message stream is just a way to capture all of these events as they happen and make them available to whoever needs them.</p>
<p><em>Imagine a live cricket match scoreboard. Every run, every wicket, every over — it's a stream of events. You can tune in now and see what's happening. Or you can rewind and check what happened in the 3rd over. The stream doesn't care when you arrive — it just keeps flowing.</em></p>
<p>Kafka is the system that <strong>captures, stores, and serves that stream</strong> to as many listeners as need it.</p>
<h2><strong>Kafka as a Central Message Pipeline</strong></h2>
<p>Instead of services talking to each other directly, every service talks to Kafka. Kafka sits in the middle — a central nervous system for your entire application.</p>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/92ef8f56-b816-4657-aea8-9afc016c0d46.png" alt="" style="display:block;margin:0 auto" />

<p>Producers don't know or care who reads their messages. Consumers don't know or care who produced them. <strong>Kafka is the only thing they both trust.</strong> This is called loose coupling — and it's the foundation of every scalable system you've ever used.</p>
<h2><strong>Producers: Who Sends Messages</strong></h2>
<p>A <strong>producer</strong> is any application that sends (publishes) messages to Kafka. Think of producers as reporters — they have news to share and they file it with the news agency (Kafka). They don't worry about who reads the article. That's not their job.</p>
<p><em>A weather station is a producer. It measures temperature every second and sends the reading to Kafka:</em> <strong>"Mumbai, 36°C, 2:30 PM."</strong> <em>It doesn't know whether the AC company, the news app, or the agriculture dashboard will read it. It just keeps sending.</em></p>
<p>Producers are responsible for two things: <strong>what message to send</strong>, and <strong>which topic to send it to</strong>. That's it. Kafka handles the rest.  </p>
<p><strong>Real world producers</strong></p>
<p>Your app's backend, IoT sensors, mobile apps, payment gateways, microservices, log aggregators — anything that generates events is a producer.</p>
<h2><strong>Topics: How Messages Are Grouped</strong></h2>
<p>Kafka doesn't just dump all messages in one pile. It organizes them into <strong>topics</strong> — named categories, like folders on your computer.</p>
<p><em>Think of a newspaper. There's a Sports section, a Business section, a Local News section. Producers (journalists) file their stories to the right section. Readers (consumers) subscribe to only the sections they care about. Topics work exactly like this.</em></p>
<p>You might have topics like <code>orders</code>, <code>payments</code>, <code>user-events</code>, <code>inventory-updates</code>. Producers write to a specific topic. Consumers read from a specific topic. <strong>Clean, organized, zero confusion.</strong></p>
<p>Topics in Kafka are <em>persistent</em> — messages don't disappear after being read. They stay for a configurable amount of time (say, 7 days). This means a new service can join and replay the entire history from day one. That's powerful.</p>
<h2><strong>Partitions: Why Messages Are Split Internally</strong></h2>
<p>Here's where it gets really clever. Each topic is split into multiple <strong>partitions</strong> — think of them as parallel lanes on a highway.</p>
<p><em>Imagine a single-lane road from Mumbai to Pune. 10,000 cars, one lane — you'll be there tomorrow. Now imagine a 6-lane expressway. Same 10,000 cars, but they spread across lanes and move in parallel. Partitions are those lanes.</em>  </p>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/843c5909-a57f-4c0d-9407-5111550fd492.png" alt="" style="display:block;margin:0 auto" />

<p>Each message within a partition gets a sequential number called an <strong>offset</strong> — like a page number in a book. Consumers bookmark their offset so they know exactly where they left off. Messages within a single partition are always in order. Across partitions, Kafka makes no ordering guarantee — but that's usually fine.</p>
<h3><strong>How does Kafka decide which partition?</strong></h3>
<p>If you send a message with a <strong>key</strong> (e.g., <code>user-id: 42</code>), Kafka hashes that key and routes all messages with the same key to the same partition — guaranteeing order for that user. No key? Kafka spreads messages across partitions evenly.  </p>
<h2><strong>Why Kafka Is Fast and Scalable</strong></h2>
<p>Kafka handles millions of messages per second. Here's the honest reason why:</p>
<p><strong>Sequential disk writes.</strong> Most databases do random reads and writes all over the disk — slow. Kafka only appends to the end of a log file, sequentially. Your hard drive was designed to do exactly this quickly. Kafka exploits this to its fullest.</p>
<p><strong>Zero-copy transfer.</strong> Normally, reading a file and sending it over the network copies the data 4 times through memory. Kafka uses a Linux trick called <em>sendfile</em> that sends data directly from disk to network in 1 step. This alone gives it a 60–70% throughput boost.</p>
<p><strong>Batching + compression.</strong> Rather than sending 1 message at a time, Kafka groups messages into batches, compresses them (GZIP/Snappy), and sends the whole batch in one network call. Fewer round trips = faster.</p>
<p><strong>Horizontal scaling via partitions.</strong> Want to handle 10× more traffic? Just add more partitions and more consumer instances. Linear scale-out, no complex re-architecture needed.</p>
<p><strong>Why Kafka is fast — summary</strong></p>
<ul>
<li><p>Appends to disk sequentially (fast I/O)</p>
</li>
<li><p>Zero-copy data transfer over network</p>
</li>
<li><p>Batches messages, compresses payloads</p>
</li>
<li><p>Scales horizontally by adding partitions</p>
</li>
<li><p>Messages stay in memory (OS page cache) for hot reads</p>
</li>
</ul>
<h2>What are Consumer Groups ?</h2>
<p>A <strong>consumer group</strong> is a team of consumers that work together to read a topic. Kafka divides the partitions among the group members so each partition is handled by exactly one consumer at a time.</p>
<p><em>Imagine 3 postmen delivering letters in a colony. Instead of all 3 delivering to every house (wasteful), each postman covers a different street. Together they cover the whole colony faster. That's a consumer group —</em> <strong>divide the work, finish faster.</strong></p>
<p>The magic rule: <strong>one partition → one consumer</strong> within a group. So if you have 6 partitions and 3 consumers in a group, each consumer handles 2 partitions. Add a 4th consumer? Rebalancing happens automatically — Kafka redistributes the partitions.</p>
<h2><strong>How Work Is Shared Across Consumers</strong></h2>
<p>This is where Kafka gets really powerful. Not only can one consumer group share a topic's load — <strong>multiple independent consumer groups can read the same topic simultaneously</strong>, each getting a full copy.</p>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/ce3e4da7-85ca-457c-a2b3-448cdb261fbe.png" alt="" style="display:block;margin:0 auto" />

<p>Group A's offset and Group B's offset are <em>completely independent</em>. Group B can be 10 minutes behind Group A — Kafka doesn't care. The messages sit there for both groups to read at their own pace. This is radically different from a traditional queue where a message is gone once one consumer reads it.  </p>
<h2><strong>How Kafka Keeps Messages Safe and Ordered</strong></h2>
<p>Kafka's durability story is built on two pillars: <strong>replication</strong> and <strong>acknowledgment</strong>.</p>
<h3>Replication</h3>
<p>Every partition has one <em>leader</em> (handles all reads and writes) and multiple <em>replicas</em> (silent backups on other machines). If the leader crashes, one replica instantly becomes the new leader. Your data doesn't disappear — it was already copied. You configure the replication factor (usually 3 in production).</p>
<h3><strong>Acknowledgment (acks)</strong></h3>
<p>When a producer sends a message, it can ask for different levels of confirmation:</p>
<ul>
<li><p>Fire and forget — no confirmation. Fastest. Data loss possible.</p>
</li>
<li><p>Leader confirms — one server confirms. Good balance.</p>
</li>
<li><p>All replicas confirm — maximum safety. Use for financial data.</p>
</li>
</ul>
<h3><strong>Ordering</strong></h3>
<p>Within a single partition, messages are <strong>strictly ordered</strong> — they are always appended and always read in sequence. Consumers track their position using offsets. If a consumer crashes and restarts, it picks up from the last committed offset — no message is skipped, no message is processed twice (with idempotent producers enabled).</p>
<h2>Conclusion</h2>
<h2><strong>So — What Is Kafka, Really?</strong></h2>
<p>Kafka is a <strong>distributed commit log</strong> that acts as the central nervous system of modern applications. It decouples producers from consumers, stores messages durably, scales horizontally through partitions, and lets multiple independent systems consume the same stream of events.</p>
<p>The one-line version: <strong>Kafka is a bulletin board that never erases anything, where everyone has their own bookmark, and new readers can start from the very first message.</strong></p>
]]></content:encoded></item><item><title><![CDATA[The Thundering Herd Problem]]></title><description><![CDATA[What Is It?
The Thundering Herd Problem happens when a large number of servers simultaneously request the same resource that just became unavailable — most commonly, an expired cache key.
Think of it ]]></description><link>https://blogs.abhijitmone.com/the-thundering-herd-problem</link><guid isPermaLink="true">https://blogs.abhijitmone.com/the-thundering-herd-problem</guid><category><![CDATA[Thundering-herd-problem]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><category><![CDATA[System Design]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Thu, 05 Mar 2026 11:59:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/d6cf520d-0f6e-4864-b057-2634cccedab7.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/0e9a9a3b-4bc2-4739-8049-f0a1b49fcf3f.png" alt="" style="display:block;margin:0 auto" />

<h1><strong>What Is It?</strong></h1>
<p>The Thundering Herd Problem happens when a large number of servers simultaneously request the same resource that just became unavailable — most commonly, an expired cache key.</p>
<p>Think of it like a store opening at 9 AM. 500 people are waiting outside. The second the door unlocks — everyone rushes in at once. The shelves collapse. The staff can't cope. <strong>Not because there were too many people overall — but because they all arrived at the exact same moment.</strong></p>
<p>Replace the store with your database. Replace the crowd with your app servers. Replace 9 AM with the moment your Redis TTL hits zero.</p>
<blockquote>
<p>⚡ It's not a volume problem — it's a <strong>synchronization</strong> problem. A thousand requests over an hour is fine. A thousand requests in the same millisecond on a cold cache is an outage.</p>
</blockquote>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/f318b17c-d28f-4413-8549-3f4f2133c9cf.png" alt="" style="display:block;margin:0 auto" />

<h2><strong>How It Happens</strong></h2>
<p>Here's the failure sequence when a cached key expires at peak traffic:</p>
<ul>
<li><p>T=0 · Cache key dropsT+1ms ·</p>
</li>
<li><p>All servers: cache MISST+2ms ·</p>
</li>
<li><p>All servers fire DB queriesT+50ms ·</p>
</li>
<li><p>DB connection pool fullT+500ms ·</p>
</li>
<li><p>Timeouts → retries (worse)T+10s · 503 errors · site down</p>
</li>
</ul>
<p>The naive code pattern that causes this looks completely innocent:  </p>
<pre><code class="language-javascript">//Looks fine. Will destroy your DB under load. 
async function getData() { let data = await redis.get('homepage'); if (!data) { 
// All 50 servers hit this at the same millisecond 
data = await db.query('SELECT * FROM articles LIMIT 20'); await redis.set('homepage', data, 'EX', 60); } return data; }
</code></pre>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/42880f6a-404a-4e2e-a9e6-c6f1ffa7ed1d.png" alt="" style="display:block;margin:0 auto" />

<h2><strong>Real-World Examples</strong></h2>
<p><strong>Hotstar / IPL</strong> — 35M concurrent viewers. A scorecard cache expiring mid-match means tens of thousands of simultaneous DB queries. Hotstar built custom thundering-herd-resistant layers for exactly this.</p>
<p><strong>Netflix</strong> — A show drops at midnight. Millions check "What's New" simultaneously. If recommendation caches were set to expire at midnight, the herd triggers at peak traffic. Netflix uses probabilistic refresh to prevent it.</p>
<p><strong>Stack Overflow</strong> — Documented using mutex-based cache refresh so only one thread rebuilds any given key, regardless of how many readers are waiting.</p>
<h2></h2>
<p><strong>How to Fix It</strong></p>
<p>Five battle-tested techniques — pick based on your use case:</p>
<p><strong>🔒 Cache Locking (Mutex)</strong> — Only one server refreshes the cache. Others wait 50ms or return stale data. One DB query instead of fifty.  </p>
<pre><code class="language-javascript">const lock = await redis.set('key:lock', '1', 'NX', 'EX', 5); if (lock) { // Only this server hits the DB 
const data = await db.query(...); await redis.set('key', data, 'EX', 60); await redis.del('key:lock'); } else { await sleep(50); // wait and retry — cache will be warm }
</code></pre>
<p><strong>🎲 TTL Jitter (Simplest fix)</strong> — Add random variance to every TTL. Keys expire at different times instead of all at once. One line of code.  </p>
<pre><code class="language-javascript">// Instead of a fixed 60s for everyone: 
const ttl = 60 + Math.floor(Math.random() * 20 - 10); // 50–70s 
await redis.set('key', data, 'EX', ttl);
</code></pre>
<p><strong>🔀 Request Coalescing</strong> — 500 requests for the same key collapse into 1 upstream DB query. All 500 wait for that single result.</p>
<p><strong>⏱ Exponential Backoff</strong> — Retry after 1s → 2s → 4s → 8s. Prevents retry storms from amplifying the failure.</p>
<p><strong>♻ Background Refresh</strong> — Refresh cache at T+55s before the 60s TTL expires. Cache is always warm. Users never cause a miss.  </p>
<img src="https://cdn.hashnode.com/uploads/covers/62d622ad3060d03288d9bd97/d060f1e7-9fc1-4376-a0c3-2fb6fbdb8238.png" alt="" style="display:block;margin:0 auto" />

<p><strong>📌 Key Takeaways</strong></p>
<ul>
<li><p>Cache expiry + many servers = synchronized DB flood</p>
</li>
<li><p>It's a synchronization problem, not a traffic volume problem</p>
</li>
<li><p>Adding more servers makes it<strong>worse</strong></p>
</li>
<li><p>TTL jitter is the simplest fix — always add it</p>
</li>
<li><p>Cache locking (mutex) is the most complete fix</p>
</li>
<li><p>Background refresh gives the best user experience</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Javascript Polyfills - Bridging the gap.]]></title><description><![CDATA[Introduction
Javascript, the Dynamic language which powers the web, is constantly evolving. While this evolution brings exciting new features, it can also create compatibility issues, older browsers might not support the latest Javascript features, l...]]></description><link>https://blogs.abhijitmone.com/javascript-polyfills-bridging-the-gap</link><guid isPermaLink="true">https://blogs.abhijitmone.com/javascript-polyfills-bridging-the-gap</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Sat, 15 Feb 2025 06:39:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739529423299/9c37dee5-118d-4a5d-b338-9282f49a332f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>Javascript, the Dynamic language which powers the web, is constantly evolving. While this evolution brings exciting new features, it can also create compatibility issues, older browsers might not support the latest Javascript features, leading to broken functionality and a frustrating user experience. This is where polyfills come to the rescue.</p>
<h1 id="heading-what-is-a-polyfill">What is a Polyfill?</h1>
<p>A polyfill is a piece of Javascript code that provides modern functionality in older browser environments which don’t natively support it. Think of it like a “Filling in the gaps” mechanism. It replicates a new feature's behaviour so your code can run smoothly across different browsers, ensuring a consistent user experience.</p>
<h1 id="heading-why-use-polyfills">Why use polyfills?</h1>
<p>The primary reason for using polyfill is to avoid situations where your web application or website doesn’t work on older browsers due to a lack of support.</p>
<h2 id="heading-future-proofing-code-using-polyfill-you-can-start-modern-javascript-features-today-knowing-that-your-code-will-continue-to-work-even-as-browsers-evolve">Future-proofing code: Using polyfill, you can start modern Javascript features today. knowing that your code will continue to work even as browsers evolve.</h2>
<h1 id="heading-let-us-now-create-our-polyfills">Let us now create our polyfills.</h1>
<h2 id="heading-we-will-start-will-foreach-functionmethod-used-in-the-iteration-of-the-array">We will start will forEach () function/method used in the iteration of the array.</h2>
<p>ForEach() function/method <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"><code>Array</code></a> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">insta</a>nce executes a provided function once for each array element.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Fist we will name the method myForEach, second we will check if the method exist in the array, </span>
<span class="hljs-comment">// If it doesnt then only we can create it</span>
<span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.prototype.myForEach) {
<span class="hljs-built_in">Array</span>.prototype.myForEach = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">callback</span>) </span>{
 <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-built_in">this</span>.length; i++) { <span class="hljs-comment">// we are using for iterating over the array and then </span>
            callback(<span class="hljs-built_in">this</span>[i], i); <span class="hljs-comment">// for each element the callback , which we have passed here as an argument</span>
        }                         <span class="hljs-comment">// callback function is called with two arguments</span>
}
}
<span class="hljs-comment">// now lets demonstrate it</span>
<span class="hljs-keyword">const</span> arr1 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span> , <span class="hljs-number">5</span>];
arr1.myForEach(<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
<span class="hljs-built_in">console</span>.log(e)
}); <span class="hljs-comment">// this will print each element in the array in the console.</span>
</code></pre>
<h2 id="heading-the-second-polyfill-we-will-have-a-look-at-is-the-map-functionmethod-instances-create-a-new-array-populated-with-the-results-of-calling-a-provided-function-on-every-element-in-the-calling-array">The second polyfill we will have a look at is the map() function/method, instances create a new array populated with the results of calling a provided function on every element in the calling array.</h2>
<pre><code class="lang-javascript"><span class="hljs-comment">// myMap method creation</span>
<span class="hljs-comment">// again we will check if it exists, if it doesnt then we will create a myMap()</span>
<span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.prototype.myMap) {
<span class="hljs-built_in">Array</span>.prototype.myMap = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">userFunction</span>) </span>{
<span class="hljs-keyword">const</span> resultArray = []; <span class="hljs-comment">//initialising an empty array</span>
         <span class="hljs-comment">// this points to an exisiting context</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i &lt; <span class="hljs-built_in">this</span>.length; i++) {
<span class="hljs-comment">// now we will push the userFunction with two arguments which are index and the element of the array </span>
<span class="hljs-comment">// by using this</span>
resultArray.push(userFunction(i, <span class="hljs-built_in">this</span>[i]);
}
<span class="hljs-keyword">return</span> resultArray[] <span class="hljs-comment">// returnning the new array </span>
}
};

<span class="hljs-comment">// testing this myArray polyfill</span>
<span class="hljs-keyword">const</span> arr1 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span> , <span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> newArr = arr.myMap(<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> e ** <span class="hljs-number">2</span>);
<span class="hljs-comment">// </span>
<span class="hljs-built_in">console</span>.log(newArr) <span class="hljs-comment">// =&gt; the output will be [1, 4, 6, 8, 10]</span>
</code></pre>
<h2 id="heading-the-third-polyfill-we-will-create-is-the-filter-method-in-javascript">The third polyfill we will create is the filter method in Javascript.</h2>
<p>The <code>filter()</code> method creates a new array filled with elements that pass a test provided by a function.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// lets create our own filter method</span>
<span class="hljs-keyword">if</span>(!<span class="hljs-built_in">Array</span>.prototype.myFilter) {
<span class="hljs-built_in">Array</span>.prototype.myFilter = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">userFunction</span>) </span>{
<span class="hljs-comment">// initializing an new array</span>
<span class="hljs-keyword">const</span> resultArray = [];
<span class="hljs-comment">// now we will again use a for loop to iterate</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i &lt; <span class="hljs-built_in">this</span>.length <span class="hljs-comment">/* currentArray length */</span>; i++) {
<span class="hljs-comment">// The loop will iterate with each element in the array;</span>
<span class="hljs-keyword">if</span>(userFunction(<span class="hljs-built_in">this</span>[i]) {
resultArray.push(<span class="hljs-built_in">this</span>[i)
<span class="hljs-comment">// element in the array, the function userFunction (which is a callback function passed to myFilter) is called with the current element (this[i]). If userFunction returns true, the element is added to the res array.</span>
}
}
<span class="hljs-keyword">return</span> resultArray;
}
}

<span class="hljs-comment">// now  check the myFilterFunction</span>
<span class="hljs-keyword">const</span> arr1 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span> , <span class="hljs-number">5</span>];
<span class="hljs-keyword">const</span> newFilter = arr1.myFilter(<span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> e %<span class="hljs-number">2</span>===<span class="hljs-number">0</span>);
<span class="hljs-built_in">console</span>.log(newFilter); <span class="hljs-comment">// output will be 2 and 4 , as it is divisble by 2 and the remainder is 0.</span>
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Polyfills are an essential tool for JavaScript developers who want to build modern, feature-rich web applications that work seamlessly across all browsers. By understanding how polyfills work and how to use them effectively, you can write cleaner, more efficient code while ensuring a consistent and enjoyable user experience for everyone.</p>
]]></content:encoded></item><item><title><![CDATA[(Teleporting Human, Understanding serialization and De serialization in Javascript) The Mission: Stellar exchange]]></title><description><![CDATA[Introduction
In the year 2405, the Starship Enterprise, under the command of Captain Jean-Luc Picard, embarks on a critical mission to establish peaceful relations with the mysterious alien civilization known as the Xelthorians. The Xelthorians posse...]]></description><link>https://blogs.abhijitmone.com/teleporting-human-understanding-serialization-and-de-serialization-in-javascript-the-mission-stellar-exchange</link><guid isPermaLink="true">https://blogs.abhijitmone.com/teleporting-human-understanding-serialization-and-de-serialization-in-javascript-the-mission-stellar-exchange</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Thu, 13 Feb 2025 11:19:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739295666014/9eceda0d-2a35-48a4-ab12-a00634059582.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>In the year 2405, the Starship Enterprise, under the command of Captain Jean-Luc Picard, embarks on a critical mission to establish peaceful relations with the mysterious alien civilization known as the Xelthorians. The Xelthorians possess advanced technology that could revolutionize Starfleet’s understanding of the cosmos. However, their language and data formats are unlike anything the Federation has encountered before.</p>
<p>To facilitate communication and data exchange, Captain Picard and his crew must serialize their data to send it across subspace communication channels and deserialize the data they receive from the Xelthorians.</p>
<h1 id="heading-serialization-preparing-data-for-subspace-transmission">Serialization: Preparing Data for Subspace Transmission.</h1>
<p>Ensign Wesley Crusher, the young and brilliant Starfleet officer, is tasked with preparing the crew's data for transmission. He gathers crucial information about the Enterprise's crew and uses JavaScript to serialize it. This process converts the data into a string format, making it easy to send over subspace communication.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Data to be serialized</span>
<span class="hljs-keyword">const</span> starFleetOfficer = {
<span class="hljs-attr">name</span>: <span class="hljs-string">"Jean-luc Picard"</span>,
<span class="hljs-attr">rank</span>: <span class="hljs-string">"Captain"</span>,
<span class="hljs-attr">ship</span>: <span class="hljs-string">"USS Enterprise"</span>,
<span class="hljs-attr">species</span>: <span class="hljs-string">"Human"</span>,
}
<span class="hljs-comment">// Serialize the object </span>
<span class="hljs-keyword">const</span> serializedData = <span class="hljs-built_in">JSON</span>.stringify(starFleetOfficer)
<span class="hljs-built_in">console</span>.log(serializedData);
<span class="hljs-comment">// the output will be</span>
<span class="hljs-comment">// {"name":"Jean-luc Picard","rank":"Captain","ship":"USS Enterprise","species":"Human"}</span>
</code></pre>
<p>Lieutenant Commander Data, the android officer renowned for his computational prowess, receives a transmission from the Xelthorians. The data arrives in a serialized format, a jumble of characters that only a machine could understand. Using JavaScript, Data deserializes the alien data, converting it back into a readable object.</p>
<h1 id="heading-deserialization-deciphering-the-data">Deserialization: Deciphering the data</h1>
<p>Now Deserialization is a process to convert the JSON string into a Javascript object again, and it is done by using JSON.parse.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> deserializedData = <span class="hljs-built_in">JSON</span>.parse(serializedData);
<span class="hljs-built_in">console</span>.log(deserializedData);
<span class="hljs-comment">// the output will be again </span>
<span class="hljs-comment">/*1111
{
  name: 'Jean-luc Picard',
  rank: 'Captain',
  ship: 'USS Enterprise',
  species: 'Human'
}
*/</span>
</code></pre>
<p>Here is how it works in a flow diagram</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739445313713/2e2e2435-1ce6-4323-a69c-39c607749aab.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-the-exchange-of-bridging-worlds">The exchange of bridging worlds</h1>
<p>The bridge of the Enterprise buzzes with activity as Wesley and Data work together. The crew’s data, now serialized, is transmitted to the Xelthorians. Moments later, Data deciphers the incoming alien data.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Crew data to be sent</span>
<span class="hljs-keyword">const</span> crewData = [
    { <span class="hljs-attr">name</span>: <span class="hljs-string">"William Riker"</span>, <span class="hljs-attr">rank</span>: <span class="hljs-string">"Commander"</span>, <span class="hljs-attr">ship</span>: <span class="hljs-string">"USS Enterprise"</span>, <span class="hljs-attr">species</span>: <span class="hljs-string">"Human"</span> },
    { <span class="hljs-attr">name</span>: <span class="hljs-string">"Data"</span>, <span class="hljs-attr">rank</span>: <span class="hljs-string">"Lieutenant Commander"</span>, <span class="hljs-attr">ship</span>: <span class="hljs-string">"USS Enterprise"</span>, <span class="hljs-attr">species</span>: <span class="hljs-string">"Android"</span> }
];

<span class="hljs-comment">// Serialize the crew data</span>
<span class="hljs-keyword">const</span> serializedCrewData = <span class="hljs-built_in">JSON</span>.stringify(crewData);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Sending data:"</span>, serializedCrewData);
<span class="hljs-comment">// Output: Sending data: [{"name":"William Riker","rank":"Commander","ship":"USS Enterprise","species":"Human"},{"name":"Data","rank":"Lieutenant Commander","ship":"USS Enterprise","species":"Android"}]</span>

<span class="hljs-comment">// Data received from the alien ship</span>
<span class="hljs-keyword">const</span> receivedData = <span class="hljs-string">'[{"name":"Spock","rank":"Commander","ship":"USS Enterprise","species":"Vulcan"},{"name":"Uhura","rank":"Lieutenant","ship":"USS Enterprise","species":"Human"}]'</span>;

<span class="hljs-comment">// Deserialize the received data</span>
<span class="hljs-keyword">const</span> deserializedAlienData = <span class="hljs-built_in">JSON</span>.parse(receivedData);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Received data:"</span>, deserializedAlienData);
<span class="hljs-comment">// Output: Received data: [ { name: 'Spock', rank: 'Commander', ship: 'USS Enterprise', species: 'Vulcan' }, { name: 'Uhura', rank: 'Lieutenant', ship: 'USS Enterprise', species: 'Human' } ]</span>
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Thanks to the combined efforts of Wesley Crusher and Lieutenant Commander Data, the Enterprise successfully establishes a data exchange with the Xelthorians. This achievement marks a significant step towards understanding and cooperation between two civilizations, bringing the galaxy closer to a future of peace and harmony.</p>
<p>With serialization and deserialization, the crew of the Enterprise bridges the gap between worlds, proving once again that in the vastness of space, knowledge and collaboration are the keys to unlocking new frontiers.</p>
<p>And so, the mission continues, boldly going where no one has gone before... 🖖😄</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Objects]]></title><description><![CDATA[Understanding Objects
In the world of programming, objects play a crucial role, they are fundamental building blocks which assist in structuring and organizing code. Objects play a pivotal role in Javascript, enabling developers to create complex str...]]></description><link>https://blogs.abhijitmone.com/javascript-objects</link><guid isPermaLink="true">https://blogs.abhijitmone.com/javascript-objects</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Tue, 11 Feb 2025 16:24:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739184022971/d6b60eff-7a18-4531-84d8-7e3d6a49f6ad.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-understanding-objects">Understanding Objects</h2>
<p>In the world of programming, objects play a crucial role, they are fundamental building blocks which assist in structuring and organizing code. Objects play a pivotal role in Javascript, enabling developers to create complex structures and manage information efficiently. In this article, we will explore the core concepts of Javascript objects, their properties, and various use cases.</p>
<h1 id="heading-what-is-a-javascript-object">What is a Javascript Object?</h1>
<p>A Javascript object is a collection of key-value pairs, where each key is known as a property name and is associated with a value. These values can be of any data type, including strings, numbers, arrays, or even objects. Objects are versatile and provide a way to group related data and functionalities.</p>
<p>Here is a way of declaring a Javascript object:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
<span class="hljs-attr">name</span>: <span class="hljs-string">"Spiderman"</span>,
<span class="hljs-attr">age</span>: <span class="hljs-string">"30"</span>,
<span class="hljs-attr">alias</span>: <span class="hljs-string">"Peter parker"</span>,
<span class="hljs-attr">occupation</span>: <span class="hljs-string">"Super hero"</span>,
}
</code></pre>
<h2 id="heading-accessing-and-modifying-properties-of-object">Accessing and modifying properties of Object -</h2>
<p>You can access and modify the properties of a Javascript object using either a dot notation or bracket notation. Let’s take a look at both approaches:</p>
<p>Dot notation</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(person.name); <span class="hljs-comment">// output will be Spiderman</span>
<span class="hljs-comment">// modifying the age of spider man, lets make him old</span>
person.age = <span class="hljs-number">40</span>;
<span class="hljs-built_in">console</span>.log(person.age) <span class="hljs-comment">// output will be the age is 40</span>
</code></pre>
<p>Bracket notation</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(person[<span class="hljs-string">"occupation"</span>]); <span class="hljs-comment">// output will be Super hero</span>
<span class="hljs-comment">// let us change it to photographer</span>
person[<span class="hljs-string">"occupation"</span>] = <span class="hljs-string">"Photographer"</span>;
<span class="hljs-built_in">console</span>.log(person[<span class="hljs-string">"occupation"</span>]); <span class="hljs-comment">// Out put will be Photographer</span>
</code></pre>
<h2 id="heading-adding-and-deleting-properties">Adding and deleting properties</h2>
<p>Javascript objects are dynamic, meaning you can add or delete properties even after the object has been created.</p>
<p>Adding a property</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// lets add nemesis of spiderman to the list</span>
person.nemesis = <span class="hljs-string">"Green goblin"</span>;
<span class="hljs-built_in">console</span>.log(person.nemesis); <span class="hljs-comment">// output: green goblin</span>
</code></pre>
<p>Deleting a property:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// lets delete or terminate the nemesis</span>
<span class="hljs-keyword">delete</span> person.nemesis;
<span class="hljs-built_in">console</span>.log(person.nemesis); <span class="hljs-comment">// output: undefined</span>
</code></pre>
<h2 id="heading-methods-in-javascript-objects">Methods in Javascript Objects</h2>
<p>Methods are functions that are associated with objects. They allow objects to perform actions and manipulate their own data. You can define and use a method within an object:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> person = {
<span class="hljs-attr">name</span>: <span class="hljs-string">"Spiderman"</span>,
<span class="hljs-attr">age</span>: <span class="hljs-string">"30"</span>,
<span class="hljs-attr">alias</span>: <span class="hljs-string">"Peter parker"</span>,
<span class="hljs-attr">occupation</span>: <span class="hljs-string">"Super hero"</span>,
<span class="hljs-attr">greet</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello, my name is "</span> + <span class="hljs-built_in">this</span>.name);
},
<span class="hljs-attr">league</span>: {
<span class="hljs-attr">avengers</span>: <span class="hljs-string">"yes"</span>,
},
};

person.greet() <span class="hljs-comment">// Output will be, Hellom my name is Spiderman</span>
</code></pre>
<h2 id="heading-iterating-in-objects">Iterating in objects</h2>
<p>To iterate over the properties of an object, you can use a <mark>for...in</mark> loop. This will allow to access each key-value pair within the object.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> key <span class="hljs-keyword">in</span> person) {
  <span class="hljs-built_in">console</span>.log(key + <span class="hljs-string">": "</span> + person[key]);
}
</code></pre>
<h2 id="heading-copying-objects">Copying objects</h2>
<p>There are several ways to copy Javascript objects, ranging from shallow to deep copies.</p>
<h3 id="heading-shallow-copy">Shallow copy</h3>
<p>A shallow copy of an object creates a new object that references the same memory locations as the original object for nested objects or arrays. This means that changes to nested objects or arrays in the copied object will also affect the original object and vice versa.</p>
<p>Example with Object.assign();</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> newPerson = <span class="hljs-built_in">Object</span>.assign({}, person);

<span class="hljs-comment">// modifying the nest object in the shallow copy</span>
newPerson.league.avengers = <span class="hljs-string">"No"</span>;
<span class="hljs-built_in">console</span>.log(person.league.avengers); <span class="hljs-comment">// No</span>
<span class="hljs-built_in">console</span>.log(newPerson.league.avengers); <span class="hljs-comment">// No</span>
</code></pre>
<p>Example with spread operator.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> newPerson = {...person}

<span class="hljs-comment">// modifying the property in the shallow copy</span>
newPerson.league.avengers = <span class="hljs-string">"Maybe"</span>;
<span class="hljs-built_in">console</span>.log(person.league.avengers); <span class="hljs-comment">// Maybe; </span>
<span class="hljs-built_in">console</span>.log(newPerson.league.avengers); <span class="hljs-comment">// Output will be Maybe</span>
</code></pre>
<h3 id="heading-deep-copy">Deep copy</h3>
<p>A deep copy of an object creates a new object with a completely separate memory location for all nested objects and arrays, this means that changes to the objects, nested objects and arrays in the copied object will not affect or change the original object and vice versa.</p>
<p>Example with JSON methods:</p>
<p>One common method to create a deep copy is by using JSON.stringify() and JSON.parse(). This method converts the object to a JSON string and then parses it back into a new object.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> deepCopy = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">JSON</span>.stringify(person));

<span class="hljs-comment">// modifying the value of the object in the deep copy</span>
deepCopy.league.avengers = <span class="hljs-string">"No"</span>;
<span class="hljs-built_in">console</span>.log(person.league.avengers) <span class="hljs-comment">// Maybe</span>
<span class="hljs-built_in">console</span>.log(deepCopy.league.avengers) <span class="hljs-comment">// No</span>
</code></pre>
<p>Understanding Objects is very important for writing robust and maintainable JS code, especially when you are working with large and complex data structures.</p>
]]></content:encoded></item><item><title><![CDATA[Javascript Basics -> Basics of giving life to a website.]]></title><description><![CDATA[Introduction
What is Javascript?
Have you ever wondered, when you click on a button for example pay button, you are taken to a form and then you fill the form on the website, and the payment is made, my friend that is nothing but Javascript working b...]]></description><link>https://blogs.abhijitmone.com/javascript-basics-basics-of-giving-life-to-a-website</link><guid isPermaLink="true">https://blogs.abhijitmone.com/javascript-basics-basics-of-giving-life-to-a-website</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Mon, 10 Feb 2025 10:19:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738932694871/6291b391-82fa-44cc-acc8-7ccbf826fe97.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>What is Javascript?</p>
<p>Have you ever wondered, when you click on a button for example pay button, you are taken to a form and then you fill the form on the website, and the payment is made, my friend that is nothing but Javascript working behind the scenes of the web application or web site 😱. Yes, you heard it right Javascript is the one that makes the website interactive for users. Now you know that, we will look into some of its basics and features.</p>
<h1 id="heading-welcome-to-the-magic-world-of-variables">Welcome to the magic world of Variables</h1>
<p>A thought must have come to your mind, what are variables, in layman's terms variables are nothing but containers where you can store your data or values. They are also known as identifiers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738943837424/43601d18-142e-4a2a-a75a-a340720e282f.png" alt class="image--center mx-auto" /></p>
<p>Here you can see various containers or boxes and their values.<br />There are two ways of declaring variables: the Implicit and the Explicit ways.</p>
<h2 id="heading-explicit-way">Explicit way</h2>
<p>The word explicit itself says that we are specifying a keyword/identifier before the variable name.</p>
<p>There are three ways in which you can declare a variable in JavaScript. var let and const. Before getting to that, we should know how to declare variables and follow certain standards.</p>
<h1 id="heading-var">Var</h1>
<p>var a = 10;</p>
<p>when we console.log here we will get the value of a is 10. Var is the global scope, which means when we declare a with the var keyword, it is accessible everywhere in the javascript program.</p>
<p>But var is loosely scoped, which means it can be re-declared or re-assigned, what it did was it caused problems in behaviour, bugs, and memory leaks, especially in large-scale projects and complex codebases.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> name = <span class="hljs-string">"ojas"</span>

<span class="hljs-built_in">console</span>.log(name);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Welcome <span class="hljs-subst">${name}</span>`</span>}
}
greet(); <span class="hljs-comment">// When I call greet function here it is taking the name reference from the top.</span>
</code></pre>
<p>The limitation of var is used to show unexpected behaviour in the program, which results in bugs, mostly in large and complex projects. To solve that two identifiers were introduced in Javascript standards and those were let and const.</p>
<h1 id="heading-let">let</h1>
<p>let identifier was introduced in ES6 standards, it is re-assignable, block-scoped, optionally initializing each to a value.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// demonstrating this through a code snipet</span>
<span class="hljs-keyword">let</span> x=<span class="hljs-number">10</span>; 
<span class="hljs-built_in">console</span>.log(x)  <span class="hljs-comment">// initialized with a value 10.</span>
<span class="hljs-comment">// let x = 20; </span>
<span class="hljs-comment">// Uncaught SyntaxError: redeclaration of let x . What this says is you cannot redeclare x again.</span>
<span class="hljs-comment">// we are also able to change the value here</span>
x = <span class="hljs-number">20</span>;
<span class="hljs-built_in">console</span>.log(x) <span class="hljs-comment">// so here it will give you x = 20 here. so we can change the value of x which is declared by using let keyword.</span>
<span class="hljs-comment">// But there is more, when we declare x again inside a curly braces , then lets see what happens</span>
{
 <span class="hljs-keyword">let</span> x = <span class="hljs-number">30</span>;
 <span class="hljs-built_in">console</span>.log(x) <span class="hljs-comment">// x = 30;  here something thing happened, we were able to re declare the x variable and assign different value to it.</span>
}
</code></pre>
<h1 id="heading-const">const</h1>
<p>const identifier was also introduced in ES6 standards, It is block scoped local variable. The value of const cannot be changed/reassigned but if it is an object then the values can be added, updated or removed.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> x; <span class="hljs-comment">// We need to initialize the value of a const, it cannot be kept uninitialized</span>
<span class="hljs-keyword">const</span> x = <span class="hljs-number">20</span>;
x = <span class="hljs-number">30</span>; <span class="hljs-comment">// in this case this will give an error which will tell value of const cannot be reassigned.</span>

<span class="hljs-keyword">const</span> names = [<span class="hljs-string">'Abhijit'</span>, <span class="hljs-string">'Bipin'</span>, <span class="hljs-string">'Ojas'</span>];
names.push(<span class="hljs-string">'Aniket'</span>) <span class="hljs-comment">// here we are adding Aniket in the array which is behind the scenes an object so, we can add this value in the array even if it is defined using a const keyword.</span>
</code></pre>
<h1 id="heading-implicit-declaration">Implicit Declaration</h1>
<p>When a user declares or assigns a value to a variable which is not declared by using var, let or const, Javascript declares that variable for you, but caution, when you declare a variable implicitly then it is always global scope, even if it is declared in a function body.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// example of declaration of variable implicitly</span>
name = <span class="hljs-string">"Abhijit"</span>
<span class="hljs-built_in">console</span>.log(name) <span class="hljs-comment">// this will print Abhijit in the console.</span>
</code></pre>
<h1 id="heading-difference-between-var-let-and-const">Difference between var let and const.</h1>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td><code>var</code></td><td><code>let</code></td><td><code>const</code></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Scope</strong></td><td>Function scope or global scope</td><td>Block scope</td><td>Block scope</td></tr>
<tr>
<td><strong>Hoisting</strong></td><td>Yes, hoisted and initialized to <code>undefined</code></td><td>Yes, hoisted but not initialized</td><td>Yes, hoisted but not initialized</td></tr>
<tr>
<td><strong>Reassignment</strong></td><td>Allowed</td><td>Allowed</td><td>Not allowed</td></tr>
<tr>
<td><strong>Redeclaration</strong></td><td>Allowed within the same scope</td><td>Not allowed within the same scope</td><td>Not allowed within the same scope</td></tr>
<tr>
<td><strong>Temporal Dead Zone</strong></td><td>No</td><td>Yes</td><td>Yes</td></tr>
</tbody>
</table>
</div><p>This is a brief introduction to variables in JavaScript and how they work.</p>
<h1 id="heading-datatypes-in-javascript">Datatypes in Javascript</h1>
<p>There are two main sets of data types in JS, those are primitive and non-primitive data types.</p>
<h1 id="heading-primitive-data-types">Primitive data types</h1>
<ul>
<li><p><strong>String</strong>: Represents a sequence of characters, for example, <code>"Hello, World!"</code>.</p>
</li>
<li><p><strong>Number</strong>: Represents both integer and floating-point numbers, for example, <code>42</code> or <code>3.14</code>.</p>
</li>
<li><p><strong>Boolean</strong>: Represents a logical entity and can have two values: <code>true</code> or <code>false</code>.</p>
</li>
<li><p><strong>Undefined</strong>: A variable that has been declared but not yet assigned a value.</p>
</li>
<li><p><strong>Null</strong>: Represents the intentional absence of any object value. It is treated as <code>falsy</code> for boolean operations.</p>
</li>
<li><p><strong>Symbol</strong>: A unique and immutable primitive value used as the key of an object property. For example, <code>Symbol('description')</code>.</p>
</li>
<li><p><strong>BigInt</strong>: Represents integers with arbitrary precision. It can handle values larger than the <code>Number</code> type. You can create a BigInt by appending <code>n</code> it to an integer, for example, <code>123n</code>.</p>
</li>
</ul>
<h1 id="heading-non-primitive-data-types">Non-primitive data types</h1>
<ul>
<li><p>Objects</p>
</li>
<li><p>Arrays</p>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// Object data type</span>
<span class="hljs-keyword">const</span> person = {
<span class="hljs-attr">name</span>:<span class="hljs-string">"Abhijit"</span>,
<span class="hljs-attr">age</span>:<span class="hljs-string">"20"</span>,
}

<span class="hljs-comment">// array data type</span>
<span class="hljs-keyword">const</span> fruits = [<span class="hljs-string">'Apple'</span>, <span class="hljs-string">'Banana'</span>, <span class="hljs-string">'Grapes'</span>]
</code></pre>
<p>This is a brief introduction to data types in JavaScript.</p>
]]></content:encoded></item><item><title><![CDATA[Contra-script, Javascript Array and Methods]]></title><description><![CDATA[Declaration of Array
This is the year 1987; we are at Jungle base.
let level1 = ['grunt', 'grunt', 'flying-soldier', 'grunt'];
// we need to engage now
console.log(level1, "Engage");

Methods in arrays
Shift()
Our hero, Bill needs to take out a few e...]]></description><link>https://blogs.abhijitmone.com/contra-script-javascript-array-and-methods</link><guid isPermaLink="true">https://blogs.abhijitmone.com/contra-script-javascript-array-and-methods</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Fri, 07 Feb 2025 09:11:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738912446998/7c16704a-61bb-429a-92b4-2250db55898f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-declaration-of-array">Declaration of Array</h1>
<p>This is the year 1987; we are at Jungle base.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> level1 = [<span class="hljs-string">'grunt'</span>, <span class="hljs-string">'grunt'</span>, <span class="hljs-string">'flying-soldier'</span>, <span class="hljs-string">'grunt'</span>];
<span class="hljs-comment">// we need to engage now</span>
<span class="hljs-built_in">console</span>.log(level1, <span class="hljs-string">"Engage"</span>);
</code></pre>
<h1 id="heading-methods-in-arrays">Methods in arrays</h1>
<h1 id="heading-shift">Shift()</h1>
<p>Our hero, Bill needs to take out a few enemies. here we use the shift method, which removes element from the start.</p>
<pre><code class="lang-javascript">level.shift();
level.shift();
<span class="hljs-built_in">console</span>.log(level1) <span class="hljs-comment">// output is level1=['flying-soldier', 'grunt'] 'grunt' and 'grunt' are terminated</span>
</code></pre>
<h1 id="heading-push">Push()</h1>
<p>Now we go ahead in the level, and new enemies appear, here we use the push method, so that we can insert new elements in the level1</p>
<pre><code class="lang-javascript">level1.push(<span class="hljs-string">"Soldier-sniper"</span>, <span class="hljs-string">"scuba-soldier"</span>, <span class="hljs-string">"Boss"</span>);
<span class="hljs-built_in">console</span>.log(level1); <span class="hljs-comment">// here we get level1=['flying-soldier', 'grunt', 'Soldier-sniper', 'scuba-soldier', 'Boss']</span>
</code></pre>
<h1 id="heading-indexof">indexOf()</h1>
<p>Now I want to locate where is the enemy in the jungle stage, so for this, we will use the index of method which will give me the position of the ‘Boss’ in the level1 array</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(level1.indexof(<span class="hljs-string">"Boss"</span>); <span class="hljs-comment">// the index will be 4. so my final enemy is located at the last.</span>
</code></pre>
<h1 id="heading-concat">Concat()</h1>
<p>Now we have to give the bill a power, but it is in a different section of the level, we need to bring it to level 1, how can we do that, We use the concat method, which will merge two arrays</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> powerups = [<span class="hljs-string">'S-wide range bullets'</span>, <span class="hljs-string">'L Laser-gun'</span>, <span class="hljs-string">'grunt'</span>];
<span class="hljs-built_in">console</span>.log(level1.concat(powerups)); <span class="hljs-comment">//  here we get level1=['flying-soldier', 'grunt', 'Soldier-sniper", 'scuba-soldier', 'Boss', 'S-wide range bullets', 'L Laser-gun']</span>
</code></pre>
<h1 id="heading-filter">filter()</h1>
<p>Now we must remove Grunt from the level 1 jungle, so what should we do? we should perform the filter method; it will return a new array which passes the test case</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> onlyGrunts = level1.filter(<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> e === <span class="hljs-string">'grunt'</span>); <span class="hljs-comment">// it will filter out grunts</span>
</code></pre>
<h1 id="heading-pop">pop()</h1>
<p>Now we need to eliminate mid-level enemies like “scuba soldiers”, and it is placed at the end of the enemies array, how will we do that, we will use the pop method, pop removes the last element in the array</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> enemies = [<span class="hljs-string">'Grunts'</span>, <span class="hljs-string">'Soldier-sniper'</span>, <span class="hljs-string">'Scuba-soldiers'</span>];
<span class="hljs-built_in">console</span>.log(enemies.pop()); <span class="hljs-comment">// output is the last element ie the Scuba-soldier is removed from the enemies list</span>
</code></pre>
<h1 id="heading-includes">includes()</h1>
<p>Now, Bill needs to check if the enemies contain sniper-soldier and how he will be able to do that. we use the includes method, This will check if the array consists of that specific value or not</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(enemies.includes(<span class="hljs-string">'Soldier-sniper'</span>)); <span class="hljs-comment">// This will give the result as true to Bill./</span>
</code></pre>
<h1 id="heading-map">map()</h1>
<p>We need to describe each element in the level1 array like what bill has encountered</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// let level1 = ['grunt', 'grunt', 'flying-soldier', 'grunt'];</span>
<span class="hljs-built_in">console</span>.log(level1.map((<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item + <span class="hljs-string">' encountered!'</span>)); <span class="hljs-comment">//  let level1 = ['grunt encountered', 'grunt encountered', 'flying-soldier encountered', 'grunt encountered'];</span>
</code></pre>
<h1 id="heading-slice">slice()</h1>
<p>now Bill needs to extract a portion of the level, we can achieve this by using the slice method, which extracts a section of an array and returns a new array</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> levelSection = level1.slice(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>); <span class="hljs-comment">// Extracts elements from index 0 to 2</span>
<span class="hljs-built_in">console</span>.log(levelSection);
</code></pre>
<h1 id="heading-unshift">unshift()</h1>
<p>Now we need to add some staring area like a wall in the level1 array, how are we going to achieve it by using the unshift method, Adds one or more elements to the beginning of an array, like adding a new starting area to the level</p>
<pre><code class="lang-javascript">level1.unshift(<span class="hljs-string">'wall'</span>, <span class="hljs-string">'wall'</span>);
<span class="hljs-built_in">console</span>.log(level1) <span class="hljs-comment">// The output will be level1 = ['wall', 'wall', 'grunt encountered', 'grunt encountered', 'flying-soldier encountered', 'grunt encountered'];</span>
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Here I have tried to explain few method of arrays in javascript in a fun way.</p>
]]></content:encoded></item><item><title><![CDATA[Demystifying the Internet 💡. Let's dive in.]]></title><description><![CDATA[What is the Internet?
The Internet is a worldwide network linking various devices, including (computers, mobiles, tablets, and gaming consoles like PS5 and Xbox). Consider it a freeway, where traffic(Data) from one plays to another and vice versa fro...]]></description><link>https://blogs.abhijitmone.com/demystifying-the-internet-lets-dive-in</link><guid isPermaLink="true">https://blogs.abhijitmone.com/demystifying-the-internet-lets-dive-in</guid><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Thu, 16 Jan 2025 16:51:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739298519992/7e1c6698-0935-424c-9109-887c31fef6a9.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-is-the-internet">What is the Internet?</h1>
<p>The Internet is a worldwide network linking various devices, including (computers, mobiles, tablets, and gaming consoles like PS5 and Xbox). Consider it a freeway, where traffic(Data) from one plays to another and vice versa from millions of endpoints. Everything is connected via cables and it’s an extensive network for connecting the entire globe, a large amount of cables are laid under seas and oceans, as shown in the figure below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736955391999/2603f97a-fffd-4546-9f60-043d3217cef5.png" alt class="image--center mx-auto" /></p>
<p>Image credits: <a target="_blank" href="https://www.submarinecablemap.com/">https://www.submarinecablemap.com/</a></p>
<h1 id="heading-working-the-internet">Working the Internet.</h1>
<p>Now that we have a basic idea of what the Internet is, let us dive deep and understand, how it works.</p>
<p>Physical Medium: A device connects through the medium of Wires.</p>
<p>a Fibre Optic Cables: These are used for long-distance connectivity, which transmits the data as light.</p>
<p>b Ethernet cables: These are used for short-distance connectivity, which also ensures direct connectivity and fast transmission.</p>
<h1 id="heading-explaining-it-further">Explaining it further</h1>
<ul>
<li><p>Physical devices like Computers, Mobile, and Tablets send and receive the data.</p>
</li>
<li><p>Internet Service Provider(ISP): These service providers play a key role in or you can say it is a medium which helps you connect to the internet.</p>
</li>
<li><p>Routers: Routers are nothing but a mechanism which guides your signal or information to reach the proper source.</p>
</li>
<li><p>Servers: Servers serve you the information, like a restaurant person getting your food and serving it. It also holds the information.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737042692018/f0b12d67-a710-4112-9205-8b6bde390e08.png" alt class="image--center mx-auto" /></p>
<p>The basic flow of how the internet works is shown in the figure above.</p>
<h1 id="heading-travel-journey-of-the-data">Travel journey of the data</h1>
<p>Consider an example when you hit www.google.com in your browser what does happen exactly behind the scenes? Let’s dive in.</p>
<p>1 User enters www.google.com in the browser, but the computer doesn’t understand www.google.com, what does the internet do it asks where can I find this www.google.com.</p>
<p>2 (Tada!) Here comes the DNS(Domain name service). This is a digital phonebook or Yellow Pages of the internet. It translates google.com to an address that the internet understands ie 142.250.191.78. so the whole crux is the DNS does is simply translate the google.com to an <strong>Internet Protocol address, which is then read correctly by the internet.</strong></p>
<p>3 After the DNS is done locating the address, the web request is made in action.</p>
<ul>
<li><p>Routers: This gives a proper direction to the request.</p>
</li>
<li><p>ISP(Internet Service Providers): These are the ones issuing connections and initiating the requests through them to the global network.</p>
</li>
<li><p>Servers: The end destination where the request is fulfilled and the response is sent back to the client's computer.</p>
</li>
</ul>
<h1 id="heading-requestresponse-cycle">Request/Response Cycle</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737045219932/501aa649-8804-4c28-b88e-fc0d752061cd.png" alt class="image--center mx-auto" /></p>
<p>The above figure shows the dataflow via the internet to the server and back.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>This is an overview of how the internet works.</p>
]]></content:encoded></item><item><title><![CDATA[Git and GitHub Basics and Guidelines]]></title><description><![CDATA[Basics
Let’s begin from scratch. What is GIT?Git is a version control system designed to track project file changes. It also helps you collaborate with other developers, so you can work in sync. It was developed by Linus Torvalds in 2005. It also all...]]></description><link>https://blogs.abhijitmone.com/git-and-github-basics-and-guidelines</link><guid isPermaLink="true">https://blogs.abhijitmone.com/git-and-github-basics-and-guidelines</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Wed, 08 Jan 2025 17:38:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1736357774207/2c76104d-5dd8-4c8c-804c-28e92d6cf899.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-basics">Basics</h1>
<p><strong>Let’s begin from scratch. What is GIT?</strong><br />Git is a version control system designed to track project file changes. It also helps you collaborate with other developers, so you can work in sync. It was developed by Linus Torvalds in 2005. It also allows or is used in integrating code snippets from different branches. Terms like Branches and Merges can be a little overwhelming a bit, but relax in this tutorial you will be familiar with these terms/jargon. Git is an open-source software, where you can install it on Windows, Linux and Mac.</p>
<p><strong>What is a Repository?</strong><br /><strong>A repository is nothing but a folder, where your files are stored. The repositories are of two types.</strong></p>
<p><strong>a) Local Repository - The folder which is present locally ie on your computer</strong></p>
<p><strong>b) Remote Repository - The folder which is located on the central server(Accessible to all).</strong></p>
<h1 id="heading-getting-started-with-git">Getting Started with Git.</h1>
<p>To install git you can visit the official website <a target="_blank" href="https://git-scm.com/downloads">https://git-scm.com/downloads</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736336647321/4bc9de98-b198-4ae5-9a89-c8f138a2e7f6.png" alt class="image--center mx-auto" /></p>
<p>You will land up here, and then according to your operating system, you can download the specific version of GIT. GIT is free to use and open source.</p>
<p>After you have done the installation, you can check if the git is installed properly or not by using this command in your command prompt or bash shell.</p>
<pre><code class="lang-plaintext">git --version
git version 2.24.0.windows.2
</code></pre>
<p>You will see the version details like “git version <a target="_blank" href="http://2.24.0.windows">2.24.0.windows</a>.2**” which is also shown in the above snippet.**</p>
<h1 id="heading-creating-an-account-with-github">Creating an account with GitHub</h1>
<p>One more thing we need to do is create an account with Github. A brief introduction to GitHub</p>
<p>GitHub is a web-based platform that uses Git for version control. It allows developers to host and manage their code repositories, collaborate on projects, and track changes. Think of GitHub as a social network for programmers, where you can share your projects and contribute to others' work.</p>
<p>Step 1</p>
<p>Go to <a target="_blank" href="https://github.com/">GitHub</a> and you will see the homepage.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736348672342/bf52cf4f-ec27-4cc9-bc92-743889684b5d.png" alt class="image--center mx-auto" /></p>
<p>Step 2<br />Click on the Signup button on the top right corner. You will proceed with filling out the information given in the image below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736348807867/acc3990f-a86e-4e74-9f65-eb8a0a3ce26f.png" alt class="image--center mx-auto" /></p>
<p>Step 3<br />After successfully creating an account, You will be able to sign in to the GitHub website or app.<br />Now that we have covered this basic sign-up tutorial, we will move ahead to understanding the basics of Git, commands like Git init, Git add, Git commit and so on.</p>
<h1 id="heading-git-basics-guide">Git Basics Guide</h1>
<p>We will be going through some commands<br />1 Initialization</p>
<p>Create a folder named chaicode-cohort</p>
<p>go into that folder.</p>
<pre><code class="lang-plaintext">// for initialzing the git repository type the following command
git init
</code></pre>
<p>what this will do is, it will create a .git folder in your chaicode-cohort folder and also which will be hidden</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736353569362/4eed698b-4455-4ee7-aa49-78966e811a40.png" alt class="image--center mx-auto" /></p>
<p>You can see it in the above image, for viewing all the folders in the chain code-cohort, we need to run the command ie using the git bash is ls -a, it will show you all the subdirectories including the .git folder.</p>
<p>When you open this folder in your code editor, ie the VS code editor, this is how it will appear</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736353776248/ee468e57-fb95-4525-8dad-0fc195246412.png" alt class="image--center mx-auto" /></p>
<p>Now if you closely look, By default git will show U besides the file name, which means the files are not being tracked, now to track those files we need to add them to git or let git know that, start tracking those files.</p>
<p>for that we use</p>
<pre><code class="lang-plaintext">git add filename // for single file 
git add . // for multiple files
</code></pre>
<p>This is also known as the staging stage, that is we are making git aware that these files are the ones you should keep track of.</p>
<pre><code class="lang-plaintext">// now suppose I want to track a single file.
git add one/info.txt
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354117453/76419bb1-00bb-45f9-a018-8628dd57ca14.png" alt class="image--center mx-auto" /></p>
<p>after using that command now you can see the info.txt U ie untracked status is changed to A, now it will be tracked or staged for commit. But this doesn’t work for large file sets, so we use</p>
<pre><code class="lang-plaintext">git add . // This commands adds everything to staged for commit
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354267963/4ef23111-94e4-470a-927e-e4f618cb6b18.png" alt class="image--center mx-auto" /></p>
<p>Here, when I use that command then you can see every untracked file U is changed to A ie it will be tracked from now on.</p>
<p>Now that the files are staged and ready to be committed in the git folder, we will commit them and specify a message, so that it can be easy for us to keep track of the commit.<br />for that, we use the command</p>
<pre><code class="lang-plaintext">git commit -m "First commit for chaicode-cohort"
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354507399/3fd2d907-a56c-43eb-8f80-33c678b886a1.png" alt class="image--center mx-auto" /></p>
<p>When I use the commit command with a message, you can see that there are 3 files changed and 2 insertions are made.</p>
<p>For viewing the Commit ID, we can use the git log</p>
<pre><code class="lang-plaintext">git log
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354617802/849b3ce7-26e2-4bf8-807f-7f00ebdd82ce.png" alt class="image--center mx-auto" /></p>
<p>When I use this command it gives me the information regarding the commit. like, commit id, Author, Message and date.</p>
<p>Now what if I make a change in info.txt and I want to see what change I made then “git status” is the command you will use</p>
<pre><code class="lang-plaintext">git status
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354789907/7a692e0a-4b70-44c1-b139-aba4457198d1.png" alt class="image--center mx-auto" /></p>
<p>You can see in the above image that I have made some changes in the info.txt and git is amazingly tracking it and showing it to me when I use the git status command.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736354927930/a75f73c8-f81f-47b0-8157-59a79057bba1.png" alt class="image--center mx-auto" /></p>
<p>after committing the new change and logging, we can see that my head has shifted to the new commit.</p>
<p>Now that we have the gist of how git works. we will move ahead to Github.</p>
<p>We will create a Remote repository accessible to all of our peers.</p>
<h1 id="heading-github-basics">GitHub basics</h1>
<p>Now we need to push the local repository to the centralized place where our peers can access it.</p>
<p>Go to <a target="_blank" href="https://github.com/">GitHub</a> and log in. You will see the home screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736355281145/93ad36cf-6ef1-4939-a959-e82b3ca59e58.png" alt class="image--center mx-auto" /></p>
<p>Here you can see the new button. click on it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736355429020/f1764fd6-815b-4a4f-8ce3-e3bb1a404a59.png" alt class="image--center mx-auto" /></p>
<p>In the above image, enter the repository name, chaicode-cohort in our case and then click on Create the repository.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736355636581/ac029c5e-08f3-45fe-bd5b-b71842a9484d.png" alt class="image--center mx-auto" /></p>
<p>Now we see the repository is created in GitHub, now we need to push our existing repository over here</p>
<p>so first we need to add the remote folder or remote origin folder here.</p>
<pre><code class="lang-plaintext">git remote add origin https://github.com/abhijitWebDev/chaicode-cohort.git
</code></pre>
<p>after adding the folder we need to set the branch ie in our case the master branch</p>
<pre><code class="lang-plaintext">git branch -M main
</code></pre>
<p>after setting the branch to main, now we are ready to push the code to the centralize folder</p>
<pre><code class="lang-plaintext">git push -u origin main
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736355978913/f497a6fd-c645-4550-aa7a-b3fe3458c7e4.png" alt class="image--center mx-auto" /></p>
<p>after using this command our local repository is also uploaded in our central repository.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1736356068853/35ec7c0f-10c0-41e4-8133-e452c25379a9.png" alt class="image--center mx-auto" /></p>
<p>The above image shows that it is successfully uploaded and now anyone can use this by cloning it.</p>
<p>I hope this is helpful.</p>
<h1 id="heading-things-to-be-followed-while-committing-to-the-central-repository">Things to be followed while committing to the central repository</h1>
<p>1 The commit message should be clear and the description should be to the point</p>
<p>2 The message body should contain whether it is a feature / bug-fix / documentation-improvement</p>
<p>3 The message body should contain the task id for ex “Ch-5506” like a task id.</p>
<p>4 Always take a pull from the main branch or release branch.</p>
<p>5 Create branches from the release branch or main branch.</p>
<p>6 Commit your changes more frequently.</p>
<h1 id="heading-this-concludes-the-tutorial">This concludes the tutorial.</h1>
]]></content:encoded></item><item><title><![CDATA[State Management in React]]></title><description><![CDATA[What is state management in React?
State management is a fundamental aspect of building modern web applications with React. It involves managing the data that drives component behaviour and appearance dynamically. From simple values to complex object...]]></description><link>https://blogs.abhijitmone.com/state-management-in-react</link><guid isPermaLink="true">https://blogs.abhijitmone.com/state-management-in-react</guid><category><![CDATA[State Management ]]></category><dc:creator><![CDATA[Abhijit Mone]]></dc:creator><pubDate>Wed, 22 May 2024 12:31:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738924366632/3df4cd3f-fb93-4b61-b10c-c0974117f861.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-is-state-management-in-react">What is state management in React?</h1>
<p>State management is a fundamental aspect of building modern web applications with React. It involves managing the data that drives component behaviour and appearance dynamically. From simple values to complex objects, a React state reflects the application’s current UI and logic state.</p>
<p>Here are some key points about state management in React:</p>
<p>1 Component State</p>
<ul>
<li><p>React Component can have its own local state.</p>
</li>
<li><p>The state is mutable and can be updated with the setState method.</p>
</li>
<li><p>Example</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Counter</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);

    <span class="hljs-keyword">const</span> increment = <span class="hljs-function">() =&gt;</span> {
      setCount(count + <span class="hljs-number">1</span>);
    };

    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Count: {count}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{increment}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }
</code></pre>
<p>  This code snippet is a React functional component called <code>Counter</code>. It uses the <code>useState</code> hook from React to manage state. The <code>useState(0)</code> initializes a state variable <code>count</code> with an initial value of 0, and <code>setCount</code> is the function used to update the <code>count</code> state.</p>
<p>  The component renders a <code>&lt;div&gt;</code> containing a <code>&lt;p&gt;</code> element that displays the current value of <code>count</code>, and a <code>&lt;button&gt;</code> element labeled "Increment". When the button is clicked, the <code>increment</code> function is called, which updates the <code>count</code> state by incrementing it by 1. This triggers a re-render of the component with the updated count value displayed.</p>
<p>  2 Lifting the state up</p>
</li>
<li><p>To share the state between components, you can lift it up to a common ancestor.</p>
</li>
<li><p>This allows multiple child components to access and modify the same state.</p>
</li>
</ul>
<p>Example</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Parent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [message, setMessage] = useState(<span class="hljs-string">''</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Child1</span> <span class="hljs-attr">message</span>=<span class="hljs-string">{message}</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Child2</span> <span class="hljs-attr">setMessage</span>=<span class="hljs-string">{setMessage}</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>This code snippet defines a React functional component called <code>Parent</code>. Inside the component, it uses the <code>useState</code> hook to create a state variable <code>message</code> initialized with an empty string and a function <code>setMessage</code> to update the <code>message</code> state.</p>
<p>The <code>Parent</code> component returns a <code>&lt;div&gt;</code> element containing two child components: <code>Child1</code> and <code>Child2</code>. It passes the <code>message</code> state variable as a prop to <code>Child1</code> and the <code>setMessage</code> function as a prop to <code>Child2</code>. This allows communication between the parent component and its child components by passing data and functions as props.</p>
<h1 id="heading-why-is-state-management-needed">Why is State management needed?</h1>
<p>State management is essential in React for several reasons:</p>
<ol>
<li><p><strong>Maintaining Component State</strong>: React components can have an internal state that determines their behaviour and appearance. State management allows components to store and update their state, triggering re-renders when the state changes.</p>
</li>
<li><p><strong>Handling User Input</strong>: State management is crucial for handling user interactions like form inputs, button clicks, and other events. By managing state, React components can respond to user input and update the UI accordingly.</p>
</li>
<li><p><strong>Managing Data</strong>: React applications often need to fetch and display data from APIs or other sources. State management enables components to store and manage this data, ensuring that the UI reflects the latest information.</p>
</li>
<li><p><strong>Passing Data Between Components</strong>: State management facilitates passing data between components in a React application. By lifting the state up to a common ancestor or using context, components can share and update data effectively.</p>
</li>
<li><p><strong>Optimizing Performance</strong>: Efficient state management can help optimize performance by minimizing unnecessary re-renders. React's reconciliation process compares the current state with the previous state to determine what needs to be updated in the DOM.</p>
</li>
</ol>
<p>Overall, state management in React is crucial for building interactive, dynamic, and data-driven applications while maintaining a clear and predictable flow of data and updates throughout the component hierarchy.</p>
<p>In the further blogs, we will analyze various tools of state management.</p>
]]></content:encoded></item></channel></rss>