<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saravana on Medium]]></title>
        <description><![CDATA[Stories by Saravana on Medium]]></description>
        <link>https://medium.com/@saravanaeswari22?source=rss-b66a5bd80e49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9aAAlqam2TgzWFoiA7Egdw.png</url>
            <title>Stories by Saravana on Medium</title>
            <link>https://medium.com/@saravanaeswari22?source=rss-b66a5bd80e49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:59:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saravanaeswari22/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[V8 Engine Internals: How JavaScript Gets Compiled]]></title>
            <link>https://medium.com/@saravanaeswari22/v8-engine-internals-how-javascript-gets-compiled-e2716636c82f?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2716636c82f</guid>
            <category><![CDATA[javascript-v8-engine]]></category>
            <category><![CDATA[turbofan]]></category>
            <category><![CDATA[hidden-class]]></category>
            <category><![CDATA[javascript-compilation]]></category>
            <category><![CDATA[javascript-performance]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 08:40:39 GMT</pubDate>
            <atom:updated>2025-10-03T08:40:39.000Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how JavaScript runs so fast in modern browsers? 🚀</p><p>When I write JavaScript code in Chrome or run it with Node.js, it executes incredibly fast — almost instantly! But here’s what’s interesting: JavaScript is traditionally an <strong>interpreted language.</strong></p><p><strong>Wait, what does “interpreted” mean?</strong> 🤔</p><p>Let me explain with a simple analogy:</p><p>Imagine you’re reading a recipe in a foreign language. You have two options:</p><p><strong>Option 1: Interpreter (Line by line translation)</strong></p><ul><li>You read the first line</li><li>Translate it to your language</li><li>Follow that instruction</li><li>Move to the next line</li><li>Translate it</li><li>Follow it… and so on</li></ul><p><strong>Option 2: Compiler (Translate everything first)</strong></p><ul><li>Translate the entire recipe to your language first</li><li>Then follow all the instructions quickly without translating</li></ul><p><strong>Interpreted languages</strong> (like JavaScript, Python) work like Option 1 — they read and execute code line by line, translating as they go.</p><p><strong>Compiled languages</strong> (like C++, Java) work like Option 2 — they translate the entire code to machine language first, then run it.</p><p>The problem? Reading and translating line by line (interpreting) is slower than having everything pre-translated (compiled).</p><p>So JavaScript should be slower, right? But somehow Chrome and Node.js make it blazingly fast! what’s the secret behind this speed?</p><p>The answer lies in <strong>The V8 Engine</strong> — a powerful JavaScript engine built by Google that completely changed how JavaScript runs.</p><p>So in this article, I’ll break down V8 step by step — with practical examples and real-world insights..</p><p>Let’s dive in! 🏊‍♂️</p><h4>First, What is V8?</h4><p>V8 is Google’s JavaScript engine. Think of it as the brain that runs your JavaScript code. It’s written in C++ and it powers:</p><ul><li>Google Chrome (that’s why Chrome is so fast!)</li><li>Node.js (yes, the same engine!)</li><li>Microsoft Edge (switched to V8 in 2020)</li></ul><p>But here’s what makes V8 special: <strong>it doesn’t just interpret JavaScript line by line</strong>.</p><p>Traditional interpreters read your code, understand it, and execute it — like reading a recipe and cooking as you go. That’s… okay, but not super fast.</p><p>V8 does something clever: it <strong>compiles JavaScript into machine code</strong> that your computer’s processor can run directly. That’s why it’s very fast!</p><h4>Let Me Explain With a Real-Life Example</h4><p>Imagine you’re opening a restaurant. You have recipes (your JavaScript code), and you need to cook the food for customers.</p><p><strong>Option 1: Interpreter</strong></p><ul><li>A cook reads the recipe line by line</li><li>Cooks one step at a time</li><li>Every single order is made this way</li><li>It works, but if someone orders the same dish 100 times? You’re reading that recipe 100 times!</li></ul><p><strong>Option 2: The V8</strong></p><ul><li>First order comes in → the cook reads the recipe and makes the dish (interpreter)</li><li>But wait! This dish is popular</li><li>The head chef memorizes the recipe and creates an optimized, super-fast process (compiler)</li><li>Now when orders come in, Food is ready in seconds</li></ul><p>That’s exactly what V8 does! It starts by interpreting (quick start), but then compiles popular code into optimized machine code (lightning fast execution). Let see thejourney.</p><h4>The Journey: How Your Code Actually Runs</h4><p>Okay, when you write JavaScript and run it, what actually happens? Let me walk you through the journey:</p><pre>Your JavaScript Code<br>        ↓<br>    🔍 Parsing<br>        ↓<br>    📋 Abstract Syntax Tree (AST)<br>        ↓<br>    ⚡ Ignition (Interpreter)<br>        ↓<br>    📊 Profiler (watching hot code)<br>        ↓<br>    🚀 TurboFan (Compiler)<br>        ↓<br>    💻 Optimized Machine Code</pre><p>Let’s say you wrote this simple function:</p><pre>function add(a, b) {<br>  return a + b;<br>}<br><br>const result = add(5, 10);</pre><p>Simple, right? But behind the scenes, V8 is doing some amazing things with this code.</p><h4>Step 1: Parsing — V8 Reads Your Code</h4><p>First, V8 needs to understand what you wrote. This is called <strong>parsing</strong>.</p><p>Think of it like this: when you read a sentence, your brain breaks it into words, identifies verbs and nouns, and understands the meaning. V8 does the same with your code!</p><p><strong>What happens:</strong></p><p>V8 breaks your code into tiny pieces called <strong>tokens</strong>:</p><ul><li>function → Oh, this is a function keyword</li><li>add → This is the function name</li><li>( → Opening parenthesis</li><li>a → First parameter</li><li>, → Comma</li><li>b → Second parameter</li><li>And so on…</li></ul><p>Then it builds an <strong>Abstract Syntax Tree (AST)</strong> — basically a tree structure that represents your code’s logic:</p><pre>FunctionDeclaration: add<br>    ├── Parameters: [a, b]<br>    └── Body:<br>         └── Return<br>              └── Add operation<br>                   ├── Left: a<br>                   └── Right: b</pre><p><strong>Why does this matter?</strong></p><p>Well, the AST is like a blueprint. It helps V8 understand: “Okay, this function takes two parameters and adds them together.”</p><p>Also, this is where V8 catches syntax errors! If you forgot a closing bracket, the parser will yell at you here.</p><h4>Step 2: Ignition — Let’s Start Running!</h4><p>After parsing, V8 hands the AST to something called <strong>Ignition</strong> — V8’s interpreter.</p><p>Now you might have question: “Wait, I thought V8 was a compiler? What’s this interpreter doing here<em>?”</em></p><p>Great question! Here’s the answer: compiling code takes time and memory. If V8 compiled everything immediately, your app would take forever to start!</p><p>So V8 uses a smart strategy:</p><ul><li><strong>Ignition</strong> (interpreter) runs your code quickly right away</li><li>Meanwhile, it watches for code that runs a lot</li><li>Then <strong>TurboFan</strong> (compiler) optimizes that hot code</li></ul><p>It’s like having a quick cook for instant orders, and a master chef who perfects the popular dishes!</p><h4>What Ignition does:</h4><p>It converts the AST into <strong>bytecode</strong> — a kind of middle ground between JavaScript and machine code.</p><p>For our add function:</p><pre>Ldar a1        // Load parameter &#39;a&#39;<br>Add a0         // Add parameter &#39;b&#39; <br>Return         // Return the result</pre><p>This bytecode runs immediately. Your code is now executing!</p><p>But V8 isn’t done yet…</p><h4>Step 3: Profiling — V8 Is Watching</h4><p>While Ignition runs your code, V8’s <strong>profiler</strong> is working in the background like a detective.</p><p>It’s asking questions:</p><ul><li>“How many times is this function called?”</li><li>“What types of data are being used? Numbers? Strings? Objects?”</li><li>“Are there any patterns here?”</li></ul><p>Let’s say you have this code:</p><pre>function calculateTotal(items) {<br>  let total = 0;<br>  for (let i = 0; i &lt; items.length; i++) {<br>    total += items[i].price;<br>  }<br>  return total;<br>}<br><br>// This function gets called 10,000 times!<br>for (let i = 0; i &lt; 10000; i++) {<br>  calculateTotal(shoppingCart);<br>}</pre><p>The profiler notices: <em>“Whoa! This </em><em>calculateTotal function is running 10,000 times! And it&#39;s always receiving an array of objects with a &#39;price&#39; property. This is HOT CODE!&quot;</em></p><p>When code becomes “hot” (runs frequently), V8 makes a decision: “Let’s optimize this!”</p><p>That’s when <strong>TurboFan</strong> enters the scene.</p><h4>Step 4: TurboFan — Maximum Optimization!</h4><p><strong>TurboFan</strong> is V8’s optimizing compiler — the master chef who perfects the recipe.</p><p>It takes that hot code and generates <strong>highly optimized machine code</strong> that runs directly on your CPU. No interpretation, no bytecode — just raw, blazing-fast machine instructions.</p><p>But how does it optimize? Let me show you some of its clever tricks:</p><p><strong>Trick 1: Inline Caching</strong></p><p>Let’s say you’re accessing object properties:</p><pre>function getPrice(product) {<br>  return product.price;<br>}<br><br>const item1 = { name: &quot;Laptop&quot;, price: 1000 };<br>const item2 = { name: &quot;Mouse&quot;, price: 25 };<br><br>getPrice(item1);  // First call<br>getPrice(item2);  // Second call</pre><p>Normally, JavaScript has to search for the price property each time. But V8 notices: <em>&quot;Hey, both objects have the same structure! I can remember where &#39;price&#39; is located!&quot;</em></p><p>So it caches the property location. Next time? Direct access. Super fast!</p><p><strong>Trick 2: Hidden Classes</strong></p><p>Okay, this one might sound mysterious, but it’s actually really cool! Let me explain what “hidden classes” are.</p><p><strong>What are Hidden Classes?</strong></p><p>You know how in JavaScript, objects can have any properties you want? You can create objects on the fly:</p><pre>const user = {};<br>user.name = &quot;Saravana&quot;;<br>user.age = 25;<br>user.city = &quot;Chennai&quot;;</pre><p>This flexibility is great for us developers, but it creates a problem for V8: How does it know where to find these properties in memory?</p><p>In languages like C++ or Java, the compiler knows exactly where each property is stored because classes are defined upfront. But JavaScript objects are dynamic!</p><p>So V8 invented <strong>hidden classes</strong> (also called “shapes” or “maps”) — it’s an internal structure that V8 creates behind the scenes to track the “shape” of your objects.</p><p>Think of it like this: When you create objects with the same properties in the same order, V8 says “okay! These objects have the same blueprint!” and it assigns them the same hidden class.</p><pre>// These two objects have the SAME hidden class<br>const obj1 = { x: 1, y: 2 };<br>const obj2 = { x: 5, y: 10 };<br>// V8 thinks: &quot;Both have properties &#39;x&#39; and &#39;y&#39; in that order. Same shape!&quot;<br><br>// But this one has a DIFFERENT hidden class!<br>const obj3 = { y: 2, x: 1 };  // Properties in different order<br>// V8 thinks: &quot;Wait, this one has &#39;y&#39; first, then &#39;x&#39;. Different shape!&quot;</pre><p><strong>Wait, why does property order matter?</strong></p><p>Because V8 uses the hidden class to figure out where properties are stored in memory. Same hidden class = same memory layout = super fast access!</p><p><strong>Here’s a real example of how this affects you:</strong></p><pre>function Point(x, y) {<br>  this.x = x;<br>  this.y = y;<br>}<br><br>const p1 = new Point(1, 2);  // V8 creates Hidden Class A<br>const p2 = new Point(5, 10); // Same structure! Uses Hidden Class A - FAST!<br><br>// But then you do this:<br>p1.z = 3;  // Added a new property!<br>// V8 creates a NEW Hidden Class B for p1 - SLOWER!</pre><p>What happened? When you added the z property to p1, its shape changed! Now p1 and p2 have different hidden classes, so V8 can&#39;t use the same optimized code for both.</p><p><strong>Why does V8 care so much about hidden classes?</strong></p><p>When objects share the same hidden class, V8 can:</p><ul><li>Reuse optimized machine code</li><li>Know exactly where properties are in memory</li><li>Make property access super fast</li></ul><p>When objects have different hidden classes, V8 has to:</p><ul><li>Generate different code for each shape</li><li>Do slower property lookups</li><li>Work much harder</li></ul><p>I’ll show you how to keep your objects using the same hidden classes (and make V8 happy!) in a bit!</p><p>wait? I have a thought: <em>“Okay, so how do I write code that V8 loves?”</em></p><p>Great question! Let me show you.</p><h4>Writing V8-Friendly Code 💡</h4><p>Now that you understand how V8 works, you can write faster JavaScript! Here’s what I learned:</p><ol><li><strong>Keep Your Types Consistent</strong></li></ol><pre>// ❌ Bad - Type changes cause deoptimization<br>function calculate(value) {<br>  return value * 2;<br>}<br><br>calculate(5);       // number<br>calculate(&quot;10&quot;);    // string - BAD!<br><br>// ✅ Good - Always use the same type<br>function calculate(value) {<br>  if (typeof value !== &#39;number&#39;) {<br>    value = Number(value);  // Convert once, upfront<br>  }<br>  return value * 2;<br>}</pre><p><strong>2. Initialize Objects the Same Way</strong></p><pre>// ❌ Bad - Different property orders<br>const user1 = { name: &quot;Saravana&quot;, age: 25 };<br>const user2 = { age: 30, name: &quot;John&quot; };  // Different order!<br><br>// ✅ Good - Same property order<br>const user1 = { name: &quot;Saravana&quot;, age: 25 };<br>const user2 = { name: &quot;John&quot;, age: 30 };</pre><p><strong>3. Don’t Add Properties Later</strong></p><pre>// ❌ Bad - Adding properties dynamically<br>function createPoint(x, y) {<br>  const point = { x: x, y: y };<br>  return point;<br>}<br><br>const p = createPoint(1, 2);<br>p.z = 3;  // Added later - changes hidden class!<br><br>// ✅ Good - Initialize all properties upfront<br>function createPoint(x, y, z) {<br>  return {<br>    x: x,<br>    y: y,<br>    z: z || 0  // Initialize even if optional<br>  };<br>}</pre><p><strong>4. Use Constructor Functions Consistently</strong></p><pre>// ✅ Good pattern<br>function Point(x, y, z) {<br>  this.x = x;<br>  this.y = y;<br>  this.z = z;<br>}<br><br>const p1 = new Point(1, 2, 3);<br>const p2 = new Point(4, 5, 6);<br>// Same hidden class! V8 is happy!</pre><p><strong>5. Avoid Try-Catch in Hot Code</strong></p><pre>// ❌ Bad - try-catch blocks prevent optimization<br>function hotFunction(x) {<br>  try {<br>    return x * 2;<br>  } catch (e) {<br>    return 0;<br>  }<br>}<br><br>// ✅ Good - Move try-catch outside hot paths<br>function safeCalculate(x) {<br>  return calculate(x);<br>}<br><br>function calculate(x) {<br>  return x * 2;  // This can be optimized!<br>}</pre><h4>A Real Example: Before &amp; After</h4><p>Let me show you how these principles work in practice.</p><p><strong>❌ Before (Slow):</strong></p><pre>function processUsers(users) {<br>  let result = [];<br>  <br>  for (let i = 0; i &lt; users.length; i++) {<br>    let user = users[i];<br>    <br>    // Type inconsistency<br>    if (typeof user.age === &#39;string&#39;) {<br>      user.age = parseInt(user.age);<br>    }<br>    <br>    // Adding properties dynamically<br>    user.processed = true;<br>    user.timestamp = Date.now();<br>    <br>    result.push(user);<br>  }<br>  <br>  return result;<br>}</pre><p><strong>Problems:</strong></p><ul><li>Type checking in every loop iteration</li><li>Adding properties dynamically (changes hidden class)</li><li>Not using optimized array methods</li></ul><p><strong>✅ After (Fast):</strong></p><pre>function processUsers(users) {<br>  return users.map(user =&gt; ({<br>    ...user,<br>    age: typeof user.age === &#39;string&#39; ? parseInt(user.age) : user.age,<br>    processed: true,<br>    timestamp: Date.now()<br>  }));<br>}</pre><p><strong>Why is this better?</strong></p><ul><li>Type normalization happens once per user</li><li>All properties initialized together (consistent hidden class)</li><li>Uses native map method (highly optimized by V8)</li><li>V8 can inline and optimize aggressively!</li></ul><h3>Conclusion:</h3><p>I hope this deep dive into V8 was helpful and not too overwhelming. If you have questions or found something confusing, let me know — I’m always happy to clarify!</p><p>Suggestions and criticisms are highly appreciated ❤️</p><p><strong>Want to learn more?</strong></p><ul><li>V8 Official Blog: <a href="https://v8.dev/blog">https://v8.dev/blog</a></li><li>V8 Documentation: <a href="https://v8.dev/docs">https://v8.dev/docs</a></li><li>Understanding V8’s TurboFan: <a href="https://v8.dev/blog/turbofan-jit">https://v8.dev/blog/turbofan-jit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2716636c82f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Memory Management and Garbage Collection Explained (with Examples)]]></title>
            <link>https://medium.com/@saravanaeswari22/javascript-memory-management-and-garbage-collection-explained-with-examples-6abb59d2c1d2?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/6abb59d2c1d2</guid>
            <category><![CDATA[memory-management-js]]></category>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[stack-and-heap]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Thu, 02 Oct 2025 12:26:21 GMT</pubDate>
            <atom:updated>2025-10-02T12:32:17.366Z</atom:updated>
            <content:encoded><![CDATA[<h3>Memory Management and Garbage Collection in Javascript</h3><p>Have you ever wondered how JavaScript actually manages memory behind the scenes? 🤔<br> As developers, we often just write code and trust that the engine handles everything — but understanding what’s happening under the hood can make a huge difference.</p><p>It helps you:</p><ul><li>Write <strong>faster, more efficient code</strong></li><li>Avoid those sneaky <strong>memory leaks</strong></li><li>Debug performance issues confidently</li></ul><p>In this article, we’ll take a <strong>closer look at memory management and garbage collection in JavaScript.</strong></p><p>let’s dive in:</p><h3>A Simple Analogy — Your Fridge &amp; The Cleaner 🧊🧹</h3><p>Think of memory like your fridge:</p><ul><li><strong>Stack</strong> → The quick-access shelf (local variables, call frames).</li><li><strong>Heap</strong> → The big storage section (objects, arrays, functions).</li><li><strong>Garbage Collector (GC)</strong> → The cleaner who throws out expired or unreachable food.</li></ul><p>👉 If you forget to throw out leftovers (unused data), your fridge (memory) fills up — slowing everything down.</p><p>above example clearly shows what are things are there in memory how it will work. now we will each things deeply and comparison.</p><h3>What is Stack?</h3><p>Remember that quick-access shelf in our fridge analogy? That’s exactly what the stack is — <strong>fast, organized, and limited in size.</strong></p><p>The stack is where JavaScript stores:</p><ul><li>Primitive values (numbers, strings, booleans, null, undefined, symbols)</li><li>Function calls and their local variables</li><li>References (pointers) to objects in the heap</li></ul><p><strong>Why is it called a “stack”?</strong> 🥞</p><p>Imagine stacking plates. The last plate you put on top is the first one you take off — that’s <strong>LIFO (Last In, First Out).</strong> JavaScript uses this same principle to manage function execution.</p><pre>function greet(name) {<br>  const greeting = &quot;Hello&quot;;<br>  const message = `Welcome, ${name}!`;<br>  return message;<br>}<br><br>const user = &quot;Saravana&quot;;<br>greet(user);</pre><p>Here’s what happens in the stack:</p><ol><li>user = &quot;Saravana&quot; gets pushed onto the stack</li><li>greet() function call creates a new frame on top</li><li>Inside that frame: greeting = &quot;Hello&quot;, name = &quot;Saravana&quot;, and message are stored</li><li>Function returns, and <strong>POP!</strong> — the entire greet() frame is removed</li><li>Back to the global context</li></ol><p><strong>Key characteristics of the stack:</strong></p><p>✅ <strong>Lightning fast</strong> — allocation and deallocation happen automatically<br> ✅ <strong>Fixed size</strong> — typically around 1MB (varies by environment)<br> ✅ <strong>Self-cleaning</strong> — when a function finishes, its memory is immediately freed<br> ✅ <strong>Predictable</strong> — memory is allocated and freed in a specific order</p><p><strong>But here’s the catch…</strong> ⚠️</p><p>Because the stack has a fixed size, you can run into a <strong>stack overflow</strong> if you go too deep:</p><pre>function recursiveFunction() {<br>  recursiveFunction(); // No stopping condition!<br>}<br><br>recursiveFunction(); // 💥 Maximum call stack size exceeded</pre><p>This is why the stack is perfect for primitive values and function calls, but <strong>not</strong> for large or unpredictable data — that’s where the <strong>heap</strong> comes in💥.</p><h3>What is the Heap?</h3><p>f the stack is your quick-access shelf, the heap is that <strong>big storage section</strong> where you keep everything that doesn’t fit on the shelf — your leftover containers, that cake from last week, bulk groceries, etc.</p><p>The heap is where JavaScript stores:</p><ul><li>Objects ({})</li><li>Arrays ([])</li><li>Functions (yes, functions are objects!)</li><li>Anything that can grow dynamically in size</li></ul><p><strong>Why do we need the heap?</strong> 🤷‍♂️</p><p>Simple! The stack is fast but limited. When you create an object, JavaScript doesn’t know how big it might grow. You might add properties, nested objects, or huge arrays later on.</p><pre>const user = {<br>  name: &quot;Saravana&quot;,<br>  age: 25<br>};<br><br>// Later, you might add more properties<br>user.address = {<br>  city: &quot;Tamil Nadu&quot;,<br>  zip: &quot;636636&quot;<br>};<br><br>user.hobbies = [&quot;reading&quot;, &quot;coding&quot;, &quot;gaming&quot;];</pre><p>The heap gives JavaScript the <strong>flexibility</strong> to handle data that changes size dynamically.</p><h3><strong>How Stack and Heap work together:</strong> 🤝</h3><p>Here’s the beautiful part — they work as a team!</p><pre>function createUser(name) {<br>  const user = {           // Object created in HEAP<br>    name: name,<br>    age: 25<br>  };<br>  return user;<br>}<br><br>const myUser = createUser(&quot;Saravana&quot;);</pre><p>Let’s break down what happens:</p><p><strong>In the Stack:</strong></p><ol><li>createUser() function call gets pushed</li><li>Variable user is created — but it only stores a <strong>reference</strong> (memory address)</li><li>Variable myUser stores the same reference</li></ol><p><strong>In the Heap:</strong></p><ol><li>The actual object { name: &quot;Saravana&quot;, age: 25 } is allocated here</li><li>It gets a memory address (let’s say 0x001)</li><li>The stack variables point to this address</li></ol><p>Think of it like this: The <strong>stack holds the address</strong> (like “Shelf 3, Shelf 2”), and the <strong>heap holds the actual item</strong>.</p><p><strong>Key characteristics of the heap:</strong></p><p>✅ <strong>Flexible size</strong> — can grow as needed (within system limits)<br> ✅ <strong>Slower access</strong> — requires following references/pointers<br> ✅ <strong>Manual cleanup needed</strong> — this is where <strong>Garbage Collection</strong> comes in!<br> ✅ <strong>Shared data</strong> — multiple variables can reference the same object</p><h4><strong>Stack vs Heap: A Quick Comparison</strong> ⚖️</h4><p>Let me show you the key differences side by side:</p><p><strong>Memory Allocation:</strong></p><ul><li><strong>Stack:</strong> Automatic and immediate when you enter a function</li><li><strong>Heap:</strong> Allocated dynamically when you create objects</li></ul><p><strong>Speed:</strong></p><ul><li><strong>Stack:</strong> ⚡ Super fast (direct memory access)</li><li><strong>Heap:</strong> 🐢 Slower (needs to follow references)</li></ul><p><strong>Size:</strong></p><ul><li><strong>Stack:</strong> Limited (~1MB, causes stack overflow if exceeded)</li><li><strong>Heap:</strong> Much larger (limited by available system memory)</li></ul><p><strong>Lifespan:</strong></p><ul><li><strong>Stack:</strong> Data lives only during function execution</li><li><strong>Heap:</strong> Data lives until no references point to it</li></ul><p><strong>Data Types:</strong></p><ul><li><strong>Stack:</strong> Primitives (number, string, boolean, null, undefined, symbol) + references</li><li><strong>Heap:</strong> Objects, arrays, functions</li></ul><p><strong>Memory Management:</strong></p><ul><li><strong>Stack:</strong> Automatic (LIFO — pop when function returns)</li><li><strong>Heap:</strong> Requires Garbage Collection</li></ul><h3><strong>Garbage Collection: The Memory Cleaner 🧹</strong></h3><p>Now we get to the star of the show — the <strong>Garbage Collector (GC)</strong>!</p><p>Remember our fridge analogy? The GC is like that cleaner who periodically checks your fridge and throws out anything you’re not using anymore. But how does it know what’s “garbage”?</p><p><strong>The Core Concept: Reachability</strong> 🎯</p><p>JavaScript uses a simple but powerful rule: <strong><em>I</em>f you can’t reach it, you don’t need it.</strong></p><p>An object is considered “reachable” if:</p><ul><li>It’s referenced by a variable in the current scope</li><li>It’s referenced by a global variable</li><li>It’s part of the current call stack</li><li>It’s referenced by another reachable object</li></ul><p><strong>Example of unreachable (garbage) data:</strong></p><pre>function createUser() {<br>  let user = {<br>    name: &quot;Saravana&quot;,<br>    age: 30<br>  };<br>  // user object created in heap<br>}<br><br>createUser();<br>// Function finished → user variable gone from stack<br>// ❌ Object in heap has NO references → GARBAGE! 🗑️</pre><p><strong>Example of reachable data:</strong></p><pre>let globalUser;<br><br>function createUser() {<br>  let user = {<br>    name: &quot;John&quot;,<br>    age: 30<br>  };<br>  globalUser = user;  // ✅ Reference saved!<br>}<br><br>createUser();<br>// Function finished, but object is still reachable via globalUser<br>// ✅ NOT garbage, will be kept in memory</pre><h4><strong>How Garbage Collection Works: Two Main Algorithms</strong> 🔧</h4><p>JavaScript engines (like V8 in Chrome/Node.js) primarily use two algorithms:</p><ol><li><strong>Mark-and-Sweep (The Main Algorithm)</strong> 🎨</li><li><strong>Generational Collection (The Optimization)</strong> ⚡</li></ol><h4><strong>Mark-and-Sweep (The Main Algorithm)</strong> 🎨</h4><p>Think of it like a treasure hunt:</p><p><strong>Mark Phase:</strong></p><ol><li>GC starts from “roots” (global variables, current call stack)</li><li>It “marks” every object it can reach</li><li>It follows all references and marks those objects too</li><li>Keeps going until all reachable objects are marked</li></ol><p><strong>Sweep Phase:</strong></p><ol><li>GC scans through the heap</li><li>Any unmarked objects? → GARBAGE! 🗑️</li><li>Frees up that memory for reuse</li></ol><h4><strong>Generational Collection (The Optimization)</strong> ⚡</h4><p>V8 discovered something clever: <strong>most objects die young!</strong></p><p>Think about it — temporary variables in functions, loop iterations, etc. They’re created and discarded quickly.</p><p>So V8 splits the heap into generations:</p><p><strong>Young Generation (Nursery):</strong></p><ul><li>New objects start here</li><li>Small space (~1–8MB)</li><li>Frequent, fast GC checks (“Scavenge”)</li><li>Most objects die here</li></ul><p><strong>Old Generation (Tenured):</strong></p><ul><li>Objects that survived multiple young GC cycles</li><li>Larger space</li><li>Less frequent GC checks</li><li>Long-lived objects (globals, closures, etc.)</li></ul><pre>// Young generation - dies quickly<br>function quickProcess() {<br>  const temp = { data: &quot;temporary&quot; };  // 💀 Dies when function ends<br>  return temp.data;<br>}<br><br>// Old generation - lives long<br>const appConfig = {  // 🌳 Lives throughout app lifetime<br>  apiUrl: &quot;https://api.example.com&quot;,<br>  timeout: 5000<br>};<br><br></pre><p><strong>The process:</strong></p><ol><li>Object created → <strong>Young generation</strong></li><li>Survives 2+ GC cycles → Promoted to <strong>Old generation</strong></li><li>Stays there until no longer reachable</li></ol><p>This makes GC much more efficient! 🚀</p><h3>Memory Leak</h3><p>Now I will tell you <strong>common Memory leak</strong> and how to avoid them. (Even with GC, you can still leak memory)</p><h4><strong>1. Global Variables (Accidental)</strong></h4><pre>function oops() {<br>  leakedVariable = &quot;I&#39;m global!&quot;;  // ❌ No var/let/const<br>}<br><br>// Fix:<br>function better() {<br>  const properVariable = &quot;I&#39;m local!&quot;;  // ✅<br>}</pre><p><strong>What Actually Happens:</strong></p><p>When you forget var, let, or const, JavaScript doesn&#39;t create a <strong>local variable</strong>. Instead, it does this:</p><ol><li>Looks for leakedVariable in the current function scope → <strong>Not found</strong></li><li>Looks in the outer scope → <strong>Not found</strong></li><li>Keeps going up → <strong>Not found</strong></li><li>Reaches global scope → <strong>Still not found</strong></li><li>JavaScript says: “Okay, I’ll create it in the <strong>global scope</strong> for you!” 🤦‍♂️</li></ol><p>So your variable becomes <strong>global</strong> automatically!</p><p><strong>Why Is This a Memory Leak?</strong> 🪤</p><p><strong>Global variables NEVER get garbage collected</strong> because:</p><ul><li>They’re always <strong>reachable</strong> from the root (global object: window in browsers, global in Node.js)</li><li>The garbage collector thinks: “This is global, so the app needs it forever!”</li><li>They stay in memory <strong>for the entire lifetime of your application</strong></li></ul><h4>2. Forgotten Timers</h4><pre>// ❌ Memory leak<br>const data = fetchHugeData();<br>setInterval(() =&gt; {<br>  console.log(data);  // Keeps data in memory forever!<br>}, 1000);<br><br>// ✅ Fix: Clear when done<br>const intervalId = setInterval(() =&gt; {<br>  console.log(data);<br>}, 1000);<br><br>// Later:<br>clearInterval(intervalId);</pre><h4>3. DOM References</h4><pre>// ❌ Memory leak<br>const elements = [];<br>function addElement() {<br>  const div = document.createElement(&#39;div&#39;);<br>  document.body.appendChild(div);<br>  elements.push(div);  // Reference kept!<br>}<br><br>// Later, you remove from DOM:<br>document.body.innerHTML = &#39;&#39;;<br>// But elements array still holds references! 🪤<br><br>// ✅ Fix: Clear references<br>elements.length = 0;</pre><h3>Conclusion:</h3><p>JavaScript handles memory for us, but understanding <strong>stack, heap, and garbage collection</strong> helps us write cleaner, faster, and more reliable code. By avoiding common mistakes like global variables, forgotten timers, or unused references, we can keep our apps efficient and bug-free.</p><p>I hope you find this article helpful for <strong>Memory Management and Garbage Collection</strong> in Javascript.</p><p><strong>Suggestions and criticisms are highly appreciated </strong>❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6abb59d2c1d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding of Prototypes in JavaScript]]></title>
            <link>https://medium.com/@saravanaeswari22/understanding-of-prototypes-in-javascript-919385ad062a?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/919385ad062a</guid>
            <category><![CDATA[prototype-chain-in-js]]></category>
            <category><![CDATA[javascript-prototype]]></category>
            <category><![CDATA[js-array-functions]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 04:38:55 GMT</pubDate>
            <atom:updated>2025-09-28T04:42:56.375Z</atom:updated>
            <content:encoded><![CDATA[<p>When you start learning JavaScript, you hear a lot about prototypes, but most explanations sound complicated. I say this from my own experience — I faced the same problem when I first started learning JavaScript.</p><p>So let’s understand it step by step with real-life examples everyone can relate to.</p><p>But before we dive into prototypes, let’s quickly refresh our understanding of <strong>objects</strong> in JavaScript. Once that’s clear, moving into prototypes will feel much easier.</p><h4>Everything in JavaScript is an Object</h4><p>👉 In JavaScript, <strong>almost everything is an object</strong>.</p><p>This includes not just plain objects, but also arrays, functions, and even special values like dates.</p><p><strong>A Quick Refresher on Objects</strong></p><p>At its core, an object in JavaScript is just a collection of <strong>key–value pairs</strong>.</p><ul><li>A <strong>key</strong> (also called a property) is usually a string.</li><li>A <strong>value</strong> can be anything — a number, string, array, function, or even another object.</li><li>If the value is a function, it’s called a <strong>method</strong>.</li></ul><pre>const person = {<br>  name: &quot;Saravana&quot;,       // key: name, value: &quot;Saravana&quot;<br>  age: 25,             // key: age, value: 25<br>  greet: function() {  // key: greet, value: function<br>    console.log(&quot;Helloo Javascript !&quot;);<br>  }<br>};<br><br>person.greet(); // &quot;Helloo Javascript !&quot;</pre><h4><strong>Arrays and Functions Are Objects Too</strong></h4><blockquote><strong>Arrays Are Special Objects</strong></blockquote><p>In JavaScript, an array is a <strong>special type of object</strong> used to store an ordered collection of multiple values under a single variable. These values are called elements, and each element is assigned a numeric position, or index, starting from 0. You probably know this already, but let’s quickly see it with an example.</p><pre>const fruits = [&quot;apple&quot;,&quot;orange&quot;,&quot;banana&quot;];<br><br>console.log(fruits[0]); // apple<br></pre><p>But under the hood, arrays are really just <strong>objects with numeric keys</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nq996N8B-4TNGm1kJUUV8w.png" /><figcaption>Array example — Chrome Devtool</figcaption></figure><p>You can even add custom properties, just like any object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_s_HoFe4CPG7ahMew7AWg.png" /><figcaption>custom properties in array — Chrome Devtool</figcaption></figure><p>👉 Arrays are <strong>objects with special behavior</strong>:</p><ul><li>Numeric keys are treated differently.</li><li>The .length property auto-updates.</li><li>They come with built-in helper methods (push, map, forEach, etc.).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aj5JgxT2-fpFfb52RZiFyw.png" /><figcaption>Build-in-Function in Array</figcaption></figure><p>So where do methods like .push() and .map() come from? Hold that thought — we’ll connect it back to prototypes soon .</p><h4>Functions Are Special Objects</h4><p>Functions might seem like just blocks of code you can call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLEKZnCkH0b1SyqbFJOKfA.png" /><figcaption>Function example — Chrome Devtool</figcaption></figure><p>But functions are actually <strong>objects that can be called</strong>.<br> That means you can attach properties to them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-b2NfgyfTBczcXcgXbN-Vg.png" /><figcaption>Properties in Function — Chrome Devtool</figcaption></figure><p>Every function also has a special .prototype property (except arrow functions).<br> This becomes important when we use functions as <strong>constructors</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVi1mesqLhjA0cDeA8gimg.png" /><figcaption>constructors — Chrome Devtool.</figcaption></figure><p>👉 Functions are <strong>objects with extra abilities</strong>:</p><ul><li>They can be <strong>called</strong> (greet()).</li><li>They can be <strong>constructed</strong> (new Person()).</li><li>They can <strong>hold properties</strong> like any other object.</li></ul><h3>Connecting Back to Prototypes</h3><p>So far, we’ve seen:</p><ul><li>Arrays are objects with numeric keys + special behaviors.</li><li>Functions are objects that can be called and used as constructors.</li></ul><p>wait here’s the question:</p><p>If arrays don’t define .push() inside them, and functions don’t define .call() inside them, where do these methods actually come from?</p><p>The answer is: <strong>Prototypes.</strong></p><ul><li>Arrays get their methods (like .push, .map) from Array.prototype.</li><li>Functions get their methods (like .call, .bind) from Function.prototype.</li><li>Regular objects get their default methods (like .toString) from Object.prototype.</li></ul><h4>This is where prototypes tie everything together.</h4><h4>What is a Prototype?</h4><p>A <strong>prototype</strong> is just another object that acts as a blueprint for other objects.<br> When you create an object, JavaScript automatically links it to a prototype, which contains shared methods and properties.</p><p>Think of it like this:</p><p>Imagine you buy a smartphone. It has its own apps, but it also inherits basic features like <strong>calling</strong> or <strong>messaging</strong> from the general “phone” blueprint.</p><h4>Example: Prototype in Action</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFzMsQfClU3gXrG6YXh2zg.png" /><figcaption>Prototype in Javascript- Chrome Devtool</figcaption></figure><p>Here’s why:</p><ul><li>The array fruits doesn’t have a push method directly.</li><li>Instead, JavaScript looks at <strong>Array.prototype</strong>, finds push there, and uses it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slMgmvAwO8S_uFkIOZD_TA.png" /><figcaption>Prototypes in Array</figcaption></figure><p>above image clearly show Array.prototype ( you can see<strong> push()</strong>, <strong>pop()</strong>, <strong>map()</strong>, <strong>filter()</strong>, etc,. )</p><p>You can create own function also in prototypes. let see theexample how it is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkfIFiCmcZuFbL2rs8cy0w.png" /><figcaption>Example in prototype</figcaption></figure><h3>What’s Happening Here?</h3><ul><li>All arrays in JavaScript share <strong>Array.prototype</strong>.</li><li>By adding a method to Array.prototype, you’re effectively giving <strong>every array</strong> access to that method.</li><li>So not just fruits, but any array you create can now use .first() and .last().</li></ul><h4>Example with Another Array</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_97KCVtEdhIh5m6BHf3a8A.png" /><figcaption>Example</figcaption></figure><p>Even though numbers didn’t define .first() itself, it inherits it from <strong>Array.prototype</strong> through the prototype chain.</p><p>⚠️ <strong>Best Practice Note:</strong></p><p>In real-world production code, you usually <strong>avoid modifying built-in prototypes</strong> (like Array.prototype) because it can cause conflicts with libraries or future JS updates. Instead, you’d write utility functions or use classes.</p><p>But for learning purposes, this example is a perfect way to understand how prototypes let you extend behavior.</p><h4><strong>The Prototype Chain</strong></h4><p>When you try to access a property or method on an object, JavaScript searches in this order:</p><ol><li>The object itself.</li><li>Its prototype.</li><li>The prototype’s prototype.</li><li>…and so on, until it reaches null.</li></ol><p>This is called the <strong>prototype chain</strong>.</p><p><strong>Visualizing the Prototype Chain</strong></p><p>Example with an array:</p><pre>numbers → Array.prototype → Object.prototype → null</pre><p>Example with a function:</p><pre>greet → Function.prototype → Object.prototype → null</pre><p>Example with a plain object:</p><pre>person → Object.prototype → null</pre><p>code Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVhcKgfQhVMxui8FvKNdow.png" /><figcaption>Example in prototypes.</figcaption></figure><p>That’s the full <strong>prototype</strong> and <strong>prototype chain</strong> in action.</p><h4><strong>Why Prototypes Matter</strong></h4><ul><li><strong>Memory Efficiency</strong> — methods like .push, .map, or .toString exist only once in the prototype, not duplicated in every object.</li><li><strong>Inheritance</strong> — objects automatically get access to their prototype’s methods.</li><li><strong>Consistency</strong> — all arrays behave the same because they share the same Array.prototype.</li></ul><h3>Conclusion:</h3><p>In this article, we started with objects, explored how arrays and functions are just special kinds of objects, and then connected it all back to prototypes.</p><p>Prototypes are the hidden blueprints that make JavaScript efficient and consistent. They explain why every array has .push(), why every function can .call(), and why every object can .toString().</p><p>Once you understand the prototype chain, you’ll see JavaScript in a whole new way: not as magic, but as a simple system of linked objects.</p><p>I hope you find this article helpful for <strong>Prototypes</strong> and it chain.</p><p><strong>Suggestions and criticisms are highly appreciated </strong>❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=919385ad062a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Webpack: How It Works and Why It’s Essential for Modern Web Development]]></title>
            <link>https://medium.com/@saravanaeswari22/understanding-webpack-how-it-works-and-why-its-essential-for-modern-web-development-6c1436070802?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c1436070802</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[modern-development]]></category>
            <category><![CDATA[bundler]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 07:22:06 GMT</pubDate>
            <atom:updated>2025-04-20T07:22:06.292Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In modern web development, managing dependencies, assets, and optimizing performance is crucial. This is where <strong>Webpack</strong> comes in — a powerful JavaScript module bundler that helps developers efficiently package and serve their applications.</p><p>Before Webpack, web browsers relied on simple &lt;script&gt; tags to load JavaScript files, but as applications grew, this approach became inefficient. Webpack revolutionized how we bundle and serve JavaScript, CSS, images, and more. Let’s dive deep into how it works and why it’s a game-changer for developers.</p><h3>How Browsers Worked Before Webpack</h3><p>Before Webpack, web applications primarily loaded multiple JavaScript files using &lt;script&gt; tags. However, this approach had several drawbacks:</p><ol><li><strong>Manual Dependency Management</strong>: Developers had to ensure scripts loaded in the correct order, leading to dependency conflicts.</li><li><strong>Performance Issues</strong>: Every script file required a separate HTTP request, slowing down the page load time.</li><li><strong>No Code Splitting</strong>: Entire files were loaded, even if only a small portion was needed.</li><li><strong>Limited Modular Support</strong>: Older browsers didn’t support modern JavaScript module systems like ES Modules or CommonJS.</li><li><strong>Does not support different file type</strong> : User should maintain images, font and css manually.</li></ol><p><strong>Webpack</strong> solves these problems by bundling all dependencies into optimized files and loading them efficiently. Let see how it will work.</p><h3>Why Use Webpack? Key Advantages</h3><h3><strong><em>1 . To Bundle Multiple Files into One</em></strong></h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>In a large project, you might have 50+ JavaScript files (.js).</li><li>If each file is loaded separately via &lt;script&gt; tags, it increases HTTP requests, slowing down page load.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li>Webpack takes all JavaScript files and bundles them into a <strong>single file (or a few files)</strong>.</li><li>This reduces HTTP requests and improves performance.</li></ul><p><strong>How It Works Internally :</strong></p><ul><li><strong>Entry Point:</strong> Webpack starts from an entry file (e.g., index.js).</li><li><strong>Dependency Graph:</strong> It analyzes imports/exports to find dependencies.</li><li><strong>Module Bundling:</strong> Combines all dependent files into a single bundle.</li></ul><pre>// index.js (Entry)<br>import { greet } from &quot;./greet.js&quot;;<br>greet();</pre><pre>// greet.js<br>export function greet() {<br>  console.log(&quot;Hello, Webpack!&quot;);<br>}</pre><p>Webpack processes this into a <strong>single bundled file</strong>.</p><h3>2. To Handle Dependencies Automatically</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>Developers had to manually ensure that scripts were loaded in the correct order.</li><li>Example: If script2.js depends on script1.js, but it&#39;s loaded first, it will break.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li>Webpack <strong>analyzes dependencies automatically</strong> and ensures they are loaded correctly.</li></ul><p><strong>How It Works Internally :</strong></p><ul><li>Webpack builds a <strong>Dependency Graph</strong> by analyzing import and require() statements.</li><li>It <strong>ensures that modules are executed in the correct order</strong>.</li></ul><p><strong>Example Process :</strong></p><ul><li>index.js imports utils.js</li><li>utils.js imports math.js</li><li>Webpack resolves this dependency tree <strong>before execution</strong>.</li></ul><h3>3. To Support ES6+ Features in Older Browsers</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>Old browsers do not support modern JavaScript features like import/export, arrow functions, async/await, etc.</li><li>Developers had to manually write <strong>polyfills</strong> or avoid new features.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li>Webpack uses <strong>Babel Loader</strong> to transpile ES6+ code into ES5 (older JavaScript version).</li></ul><p><strong>How It Works Internally :</strong></p><ul><li>Webpack detects .js files.</li><li>It applies <strong>Babel transformations</strong> via babel-loader.</li><li>The output is converted into an older JavaScript format.</li></ul><p><strong>Example (Modern Code)</strong></p><pre>const greet = () =&gt; console.log(&quot;Hello Webpack!&quot;);</pre><p><strong>Transpiled Output (for old browsers)</strong></p><pre>&quot;use strict&quot;;<br>var greet = function () {<br>  console.log(&quot;Hello Webpack!&quot;);<br>};</pre><p>This ensures compatibility with older browsers like IE11.</p><h3>4. To Optimize Performance (Minification &amp; Tree-Shaking)</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>JavaScript files were <strong>not optimized</strong>, making websites slow.</li><li>Unused code remained in the final bundle, increasing file size.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li><strong>Minification:</strong> Webpack removes whitespace, comments, and shortens variable names.</li><li><strong>Tree-Shaking:</strong> Webpack removes unused code <strong>automatically</strong>.</li></ul><p><strong>How It Works Internally :</strong></p><ul><li>Webpack’s <strong>TerserPlugin</strong> minifies JavaScript.</li><li>Webpack’s <strong>Tree-Shaking</strong> eliminates unused exports.</li></ul><p><strong>Example :</strong></p><pre>// math.js<br>export function add(a, b) {<br>  return a + b;<br>}<br>export function subtract(a, b) {<br>  return a - b;<br>}</pre><pre>// index.js<br>import { add } from &quot;./math.js&quot;;<br>console.log(add(2, 3));</pre><p><strong>Without Tree-Shaking (Before Webpack)</strong></p><ul><li>Both add and subtract functions are included in the final bundle.</li></ul><p><strong>With Tree-Shaking (Webpack)</strong></p><ul><li>Webpack <strong>removes </strong><strong>subtract</strong> because it&#39;s never used.</li></ul><h3>5. To Enable Code Splitting (Faster Load Time)</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>Large JavaScript files slow down the initial page load.</li><li>Users might only need a small part of the code initially.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li>Webpack splits code into <strong>smaller chunks</strong> that load on demand.</li></ul><p><strong>How It Works Internally :</strong></p><ul><li>Webpack dynamically loads JavaScript files <strong>only when needed</strong>.</li><li>Uses import() instead of static import.</li></ul><p><strong>Example :</strong></p><pre>// index.js<br>document.getElementById(&quot;btn&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  import(&quot;./alert.js&quot;).then((module) =&gt; {<br>    module.showAlert();<br>  });<br>});</pre><pre>// alert.js<br>export function showAlert() {<br>  alert(&quot;Hello from Webpack!&quot;);<br>}</pre><p><strong>Before Webpack :</strong></p><ul><li>alert.js loads with the main bundle.</li></ul><p><strong>With Webpack (Code Splitting) :</strong></p><ul><li>alert.js loads <strong>only when the button is clicked</strong>.</li></ul><h3>6. To Support Different File Types(CSS,Images, Fonts)</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>Browsers don’t support import for CSS, images, or fonts.</li><li>Developers had to manually manage styles and assets.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li>Webpack <strong>treats CSS, images, and fonts as modules</strong>.</li><li>Uses loaders like: <br>css-loader for CSS<br>file-loader for images and fonts</li></ul><p><strong>How It Works Internally :</strong></p><p>Example: Importing CSS in JavaScript</p><pre>import &quot;./styles.css&quot;;</pre><p>Webpack Process</p><ul><li>css-loader converts CSS into JavaScript.</li><li>style-loader injects CSS into the DOM at runtime.</li></ul><p>The same applies to <strong>images</strong></p><pre>import logo from &quot;./logo.png&quot;;<br>document.getElementById(&quot;img&quot;).src = logo;</pre><p>Webpack <strong>converts the image into a Base64 string</strong> or moves it to the dist/ folder.</p><h3>7. To Enable Hot Module Replacement (HMR)</h3><p><strong>Problem (Before Webpack) :</strong></p><ul><li>Every time a developer made changes, they had to <strong>refresh the page manually</strong>.</li><li>This slowed down development.</li></ul><p><strong>How Webpack Solves It :</strong></p><ul><li><strong>Hot Module Replacement (HMR)</strong> updates the code <strong>without a full page reload</strong>.</li></ul><p><strong>How It Works Internally :</strong></p><ul><li>Webpack watches for file changes.</li><li>Only the changed module is replaced in the browser.</li></ul><p><strong>Example (with Webpack HMR)</strong></p><pre>if (module.hot) {<br>  module.hot.accept(&#39;./app.js&#39;, function () {<br>    console.log(&quot;App updated!&quot;);<br>  });<br>}</pre><p><strong>Before Webpack</strong></p><ul><li>Refresh the page every time.</li></ul><p><strong>With Webpack HMR</strong></p><ul><li>Webpack updates only the changed part <strong>instantly</strong>.</li></ul><h3>Conclusion</h3><p>Before Webpack, managing JavaScript in browsers was <strong>manual, slow, and inefficient</strong>.</p><p>Webpack automates:</p><p>✅ <strong>Bundling</strong><br> ✅ <strong>Dependency resolution</strong><br> ✅ <strong>Code optimization (minification, tree-shaking, code splitting)</strong><br> ✅ <strong>Transpiling modern JS for old browsers</strong><br> ✅ <strong>Handling CSS, images, and fonts</strong><br> ✅ <strong>Hot Module Replacement for faster development</strong></p><p>I hope you find this article helpful for Webpack and it advantage.</p><p><strong>Suggestions and criticisms are highly appreciated</strong> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c1436070802" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Discovered the Joy of Reading ♥️]]></title>
            <link>https://medium.com/@saravanaeswari22/how-i-discovered-the-joy-of-reading-%EF%B8%8F-257c9c21fce6?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/257c9c21fce6</guid>
            <category><![CDATA[book-learning]]></category>
            <category><![CDATA[reading-books]]></category>
            <category><![CDATA[book-habits]]></category>
            <category><![CDATA[books-lover]]></category>
            <category><![CDATA[books]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sun, 22 Dec 2024 11:03:20 GMT</pubDate>
            <atom:updated>2024-12-22T11:03:20.686Z</atom:updated>
            <content:encoded><![CDATA[<p>After nearly two years of silence in this space, I’m returning with something unexpectedly different. As someone who typically shares insights and experiences from the world of technology, this article marks a significant departure from my usual content. But sometimes, the most meaningful stories are the ones that spring from the heart. This is a tale about rediscovering the joy of reading and the friend who helped reignite my long-dormant passion for books.</p><p>Every hobby has its beginnings, and my journey with reading started with a simple goal: to improve my vocabulary for my career. Unfortunately, it didn’t go as planned. I approached reading as a chore like another task on my professional development checklist ✅. There was no joy in it, just flipping of pages with my mind focused on career rather than the stories themselves. The books became tools rather than adventures, and unsurprisingly, this approach left me feeling disconnected and uninspired.</p><p>This year began with an unexpected encounter that would change everything. Before meeting her (more on this mysterious friend later), books were merely tools gathering dust on my shelves, sometimes serving as nothing more than decorative pieces in my place. I had always admired people who could lose themselves in novels, those who seemed to live a thousand lives through the pages they read. Their ability to disappear into stories fascinated me.</p><p>The person I met on January 2nd this year is one of the kindest souls I’ve ever encountered. With her perpetual smile and a charming mole on her nose that adds to her beauty. I never imagined we would become so close, but life has its own wonderful surprises. Over time, her genuine passion for books began to influence me, gently pulling me into the world of books📕. The way her face lights up when she talks about a novel that touched her heart, or how animated she becomes describing a story that changed her perspective on life. What inspired me most was learning that her love for books had actually led to her career. Her journey from being a passionate reader to turning that passion into a profession👩‍💻👩‍💻 showed me that reading could be more than just a hobby, it could be transformative.</p><p>I still remember the day she handed me a book and said with unwavering conviction, “You will love this one.” It was Charlotte’s Web. At first, I was skeptical — the book’s 200-plus pages seemed daunting, and I silently questioned if I could make it through such a lengthy read. The thickness of the book alone made me doubt myself. But there was something about her confidence in me, her certainty that I would connect with the story, that sparked my curiosity.</p><p>After a week, I finally opened the book. A few pages in, something unexpected happened. I couldn’t put it down. Within two hours, I had devoured nearly 100 pages. The story of Wilbur (the pig) and Charlotte (the spider), and their beautiful friendship journey, resonated with me in ways I hadn’t anticipated.</p><p>As I turned the last page, just five hours after starting, I felt a whirlwind of emotions: satisfaction, wonder, and a touch of regret that I hadn’t discovered this joy earlier. The book that had initially intimidated me with its length had become a beautiful story. I immediately called her to share my thoughts. She laughed, her voice warm with knowing delight, and said, “See? I knew you would like this book.”</p><p>After that experience, I began to understand how books could stir deep feelings and teach profound lessons. With her guidance, I’m going to explore different genres — romance, mystery, fantasy, and self-help. Each book will give new experiences, ideas, and emotions into my life. Some made me laugh until my sides hurt; others moved me to tears and left me contemplating life for days.</p><p>And now, I can finally reveal the name of this remarkable person who transformed my relationship with reading. She is <strong>Roshni</strong>, my closest friend and favorite person❤️ forever for me.</p><p>If you’ve ever thought about reading but didn’t know where to start, I urge you to take that chance. Simply pick up a book that catches your eye — just as I did with Charlotte’s Web. Who knows? Like me, you might find that one book, one story, one friend can change your life in the most unexpected and beautiful ways.</p><figure><img alt="List of books that I read." src="https://cdn-images-1.medium.com/max/1024/1*Yo5yijhd6pMB0Dmtq5_WHg.jpeg" /></figure><p>Thanks for reading.</p><p>With love ♥️,<br>Saravana.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=257c9c21fce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monorepos]]></title>
            <link>https://medium.com/@saravanaeswari22/monorepos-73f3b5528a07?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/73f3b5528a07</guid>
            <category><![CDATA[why-monorepo]]></category>
            <category><![CDATA[polymono-vs-monorepo]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[features-of-monorepo]]></category>
            <category><![CDATA[monorepo-tools]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Fri, 21 Apr 2023 11:34:53 GMT</pubDate>
            <atom:updated>2023-04-22T05:01:42.191Z</atom:updated>
            <content:encoded><![CDATA[<p>Monorepos are hot topic, especially among the web developers. In this article what we are going to cover :</p><ul><li>What is Monorepo ?</li><li>Why and when it is helpful ?</li><li>Features of a Monorepo</li><li>Monorepo tools</li></ul><p>So let’s dive in!</p><h3>What is Monorepo ?</h3><blockquote><strong>A Monorepo is a single repository containing multiple distinct projects, with well-defined relationships.</strong></blockquote><p>A monorepo is single repository that contains all of the code for an organization’s projects. Rather than having separate repositories for each project.</p><p>In monorepo, the code for each project or component is stored in subdirectory within the main directory. This allow easy navigation between projects and simplifies the process of managing dependencies between components or projects.</p><figure><img alt="monorepo example image" src="https://cdn-images-1.medium.com/max/1024/1*YLb3YqeHKVPPi4wznbzFXg.jpeg" /></figure><p>The above image is an example of a mono repo. Here packages folder is the root folder and it contains three subdirectories which are components, next-client, and strapi-cms. Each subdirectory treats as a separate project such as components that are used on the next-client side and strapi-cms used for CMS data for the next-client.</p><h3>Why monorepo and when it is useful?</h3><p>Let’s say the opposite of monorepo is a “polyrepo”. A polyrepo is the current standard way of developing applications: a repo for each team, application, or project. And it’s common that each repo has a single build artifact, and simple build pipeline. But here some drawbacks of polyrepo such as:</p><ul><li><strong>Cumbersome code sharing</strong> : To share code across repositories, you’d likely create a repository for the shared code. Now you have to set up the tooling and CI environment, add committers to the repo, and set up package publishing so other repos can depend on it. And let’s not get started on reconciling incompatible versions of third party libraries across repositories…</li><li><strong>Significant code duplication</strong> : No one wants to go through the hassle of setting up a shared repo, so teams just write their own implementations of common services and components in each repo. This wastes up-front time, but also increases the burden of maintenance, security, and quality control as the components and services change.</li><li><strong>Costly cross-repo changes to shared libraries and consumers : </strong>Consider a critical bug or breaking change in a shared library: the developer needs to set up their environment to apply the changes across multiple repositories with disconnected revision histories. Not to speak about the coordination effort of versioning and releasing the packages.</li><li><strong>Inconsistent tooling : </strong>Each project uses its own set of commands for running tests, building, serving, linting, deploying, and so forth. Inconsistency creates mental overhead of remembering which commands to use from project to project.</li></ul><p>But a monorepo can be useful approach for managing complex projects with multiple components or service and also it helpful in above drawbacks.</p><ul><li><strong>No overhead to create new projects : </strong>Use the existing CI setup, and no need to publish versioned packages if all consumers are in the same repo.</li><li><strong>Atomic commits across projects : </strong>Everything works together at every commit. There’s no such thing as a breaking change when you fix everything in the same commit.</li><li><strong>One version of everything : </strong>No need to worry about incompatibilities because of projects depending on conflicting versions of third party libraries.</li><li><strong>Developer mobility : </strong>Get a consistent way of building and testing applications written using different tools and technologies. Developers can confidently contribute to other teams’ applications and verify that their changes are safe.</li></ul><h3><strong>Monorepo features</strong></h3><p>Monorepos have a lot of advantages, but to make them work you need to have the right tools. As your workspace grows, the tools have to help you keep it fast, understandable and manageable.</p><p><strong>Manageable</strong></p><ul><li>Source code sharing</li><li>Consistent tooling</li><li>Code generation</li><li>Project constraints and visibility</li></ul><p><strong>Understandable</strong></p><ul><li>Workspace analysis</li><li>Dependency graph visualization</li></ul><p><strong>Fast</strong></p><ul><li>Local computation caching</li><li>Local task orchestration</li><li>Distributed computation caching</li><li>Distributed task execution</li><li>Transparent remote execution</li><li>Detecting Affected projects/packages</li></ul><h3><strong>Monorepo tools</strong></h3><p>There are several monorepo tools available that can be help to manage our codebase more efficiently.</p><ul><li><a href="https://bazel.build/">Bazel</a> (by Google)</li><li><a href="https://gradle.org/">Gradle Build Tool</a> (by Gradle,Inc)</li><li><a href="https://microsoft.github.io/lage">Lage</a>, <a href="https://rushjs.io/">Rush</a>(by Microsoft)</li><li><a href="https://lerna.js.org/">Lerna</a>, <a href="https://nx.dev/">Nx</a> (by Nrwl)</li><li><a href="https://www.pantsbuild.org/">pants</a> (by the Pants Build community)</li><li><a href="https://turbo.build/">Turborepo</a> (by Vercel)</li></ul><p>Particularly, I was very much interested in Lerna and it very popular. Interested in detailed trade-offs of each of the above tools — check out this amazing resource <a href="https://monorepo.tools/">here</a>.</p><p>Also, you can chime into the community interests here at <a href="https://2022.stateofjs.com/en-US/libraries/monorepo-tools/">The State of JS 2022</a> survey.</p><p>Coming to benchmarking, <a href="https://github.com/vsavkin">Victor Savkin</a> the co-founder of <a href="https://nrwl.co/">nrwl.co</a> and the creator of <a href="https://nx.dev/">Nx</a> came up with this interesting benchmarking at the time turborepo shipped. The below repo has Nx, Turbo, Lerna, and Lage enabled &amp; customizable to our needs.</p><p>Repo — <a href="https://github.com/vsavkin/large-monorepo">https://github.com/vsavkin/large-monorepo</a></p><p>Depending on your specific needs, you may find that one of these tools is more suitable for you project than others.</p><p>I hope you find this article helpful for monorepo.</p><p><strong>Suggestions and criticisms are highly appreciated</strong> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73f3b5528a07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revalidating Data in Next js]]></title>
            <link>https://medium.com/@saravanaeswari22/revalidating-data-in-next-js-961a1a17de4a?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/961a1a17de4a</guid>
            <category><![CDATA[revalidation-data]]></category>
            <category><![CDATA[data-fetching]]></category>
            <category><![CDATA[on-demand-revalidation]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[background-revalidation]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 13:22:04 GMT</pubDate>
            <atom:updated>2023-04-20T13:22:04.155Z</atom:updated>
            <content:encoded><![CDATA[<p>Next js is popular React framework that allows developer to build server side rendered application with ease. Here one of the challenges of building any application is ensuring that data is being up-to-date. In this article, what we will cover:</p><ul><li>What is Revalidating data?</li><li>Types of revalidation</li></ul><p>So let’s dive in!</p><h3>What is Revalidating data?</h3><p>Revalidation is the process of checking whether that data in the cache is still valid or not. This is important because data can be old or outdated and even incorrect over the time. Revalidating data ensures that data is always up to data and consistent with latest changes. It allows you to update specific static routes <strong>without needing to rebuild your entire site</strong>. Revalidation (also known as ISR (Incremental Static Regeneration)) allows you to retain the benefits of static while scaling to millions of pages.</p><p>There are <strong>two types of revalidation</strong> in Next js:</p><ul><li><strong>Background Revalidation</strong></li><li><strong>On-demand Revalidation</strong></li></ul><p><strong>Background Revalidation:</strong></p><p>To revalidate cached data at a specific interval, you can use “next.revalidate” option in <strong>fetch()</strong> to set the cache lifetime of resource (in seconds).</p><pre>fetch(&#39;https://dummyapi.com&#39;,{next:{revalidate:60}});</pre><p>If you want to revalidate data that does not use <strong>fetch()</strong>, you can use the route segment config.</p><p><strong>How it works:</strong></p><ul><li>When a request is made to the route that was statically rendered at build time, it will initially show the cached data</li><li>Any requests to the route after the initial request and before 60 seconds are also cached and instantaneous.</li><li>After the 60-second window, the next request will still show the cached (stale) data.</li><li>Next.js will trigger a regeneration of the data in the background.</li><li>Once the route generates successfully, Next.js will invalidate the cache and show the updated route. If the background regeneration fails, the old data would still be unaltered.</li></ul><p>When a request is made to a route segment that hasn’t been generated, Next.js will dynamically render the route on the first request. Future requests will serve the static route segments from the cache.</p><p><strong>On-demand Revalidation:</strong></p><p>If you set a revalidate time of 60, all visitors will see the same generated version of your site for one minute. The only way to invalidate the cache is if someone visits the page after the minute has passed.</p><p>Next.js supports On-Demand Incremental Static Regeneration to manually purge the Next.js cache for a specific page. This makes it easier to update your site when:</p><ul><li>Content from your headless CMS is created or updated.</li><li>Ecommerce metadata changes (price, description, category, reviews, etc.,</li></ul><p><strong>Difference between Background revalidation and on-demand revalidation:</strong></p><ol><li>Background revalidation is update the data at regular interval in the background, while on-demand revalidation update the data only when it is requested by the user.</li><li>User experience in background revalidation is always up-to-date, oin on-demand revalidation may be slightly out of date until user request the route.</li><li>Background revalidation best for frequently changing data that needs ti be updated in the background without requiring user interactions. On-demand revalidation best for data that doesn’t change frequently and only needs to be updated when user interacts with the route.</li></ol><h3>Conclusion:</h3><p>Both techniques have their advantages and disadvantages, and the choice of which technique to use will depend on the specific use case and requirement of the project.</p><p>I hope you find this article helpful for Revalidation Data in next Js.</p><p><strong>Suggestions and criticisms are highly appreciated</strong> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=961a1a17de4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding of Internet Cookies ]]></title>
            <link>https://medium.com/@saravanaeswari22/understanding-of-internet-cookies-5ad88712826b?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ad88712826b</guid>
            <category><![CDATA[http-cookie]]></category>
            <category><![CDATA[internet-cookies]]></category>
            <category><![CDATA[session-cookie]]></category>
            <category><![CDATA[privacy-concern]]></category>
            <category><![CDATA[browser-cookies]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sat, 15 Apr 2023 13:16:38 GMT</pubDate>
            <atom:updated>2023-04-15T13:16:38.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*11AAboWerhM968mArLVErg.jpeg" /></figure><p>Internet Cookies are an important part of the modern web browsing experience. So that, what we will cover in this article:</p><ul><li>What are Cookies?</li><li>Why Cookies?</li><li>How Cookies work?</li><li>Types of Cookies</li><li>Real time examples</li></ul><p>So let’s dive in!</p><h3>what are Cookies?</h3><p>Internet Cookies are also knows as HTTP cookies, which are small text files that are stored on a user’s computer or mobile device by web browser. These cookies are used to remember user preference. login details, and other data that can be used to personalize the user’s experience on a website.</p><p>Cookies are created by websites when a user visit them for first time. The website sends small amount of data to user’s browser, which are stored in user’s computer, it looks like Name-Value pair.</p><p>When the user visit the website again, the browser send the cookies back to the website, allowing it to remember the user’s preference and provide personalized experience.</p><h3>why Cookies?</h3><p>Cookies can be used for variety of use case, such as:</p><ul><li>User Authentication: Cookies can be used to remember user login information allowing them to access website without having to enter their credential each time.</li><li>Session management: Cookies can be used to maintain session information, such ad the user’s shopping art items.</li><li>Personalization: Cookie can be used to remember a user’s preference and provide customized content or recommendation.</li><li>Analytics: Cookies can be used to track user behavior on a website, such as which pages they visit how long they spend on each page. This data can be used to improve website performance and user experience.</li></ul><h3>How Cookies Work?</h3><p>When you visit a website, it can create a cookies and store it on your computer or device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N29-eBs1-pH6QnmCfBZVBg.png" /></figure><p>The cookies can contain information about your browsing habits, such as page you visited, the time you spend on each apge, and the link you clicked on. Cookies can also store information about you login credentials, such as your username and password, so that you don’t have to enter them every time you visit page or website and also browser sends the cookies back to server, allowing the website to recognize you and provide a personalized experience.</p><h3>Types of Cookies?</h3><p>There are several types of cookies that can be created by a website.</p><p><strong>Session Cookies</strong> : These cookies are created when you visit website and are deleted when you close your browser. They are used to store information about your browsing session, such as the pages you visited and the links you clicked on.</p><p><strong>Persistent Cookies : </strong>These cookies are stored on your computer or device and are not deleted when you close your browser. They can be used to tore information about your preference and login credentials.</p><p><strong>First-Party Cookies : </strong>These cookies are created by website that you are visiting. They can be used to store information about browsing habits and preference.</p><p><strong>Third-Party Cookies</strong> : These cookies are created by a website other than the one that you are visiting. They are often used for <strong>advertising and tracking purposes.</strong></p><p>While cookies can be useful tool for both user and website owners, they can also raise privacy concerns. Third-party cookies, in particular have been criticized for their use in online advertising and tracking.</p><p>Advertisers can use cookies to track your browsing habits across multiple website and use that information to serve targeted ads.</p><p>To address these concerns, many browsers now offering to block third-party cookies or limit their use.</p><h3>Real time Example</h3><p>There are some real-time examples such as,</p><ul><li>Login Information</li><li>Shopping Cart</li><li>Personalization</li><li>Analytics</li><li>Advertising</li></ul><p>now let deeply look into shopping cart example.</p><p>When you add items to your shopping cart, a cookies is created that store the items in your cart. This allow the website to remember what you added to your cart even if you leave the website and come back later.</p><p>The cookie typically contains a unique identifier that is associated with your shopping cart, as well as information about the items you have added to your cart, such as product name, quality and price.</p><p>When you return to the website, the website reads the cookies and retrieves the information about your shopping cart, so that it can display the items you have added to your cart.</p><p>if you add more or remove items, the cookies is updated accordingly. This allows for a seamless shopping experience, where you can add items to your cart and come back to them later without having to start over. It also allow the website to keep track of inventory and recommends related items based on what you have added to your cart.</p><p>Cookies are an important part of the e-commerce experience and used to provide a personalized a nd convenient shopping experience for customers.</p><h3>Conclusion:</h3><p>In this article you’ve learned:</p><ul><li>What is cookies and how it works</li><li>Real time example.</li></ul><p>I hope you find this article helpful for Cookies.</p><p><strong>Suggestions and criticisms are highly appreciated </strong>❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ad88712826b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Revolutionize your styling with Stitches]]></title>
            <link>https://medium.com/@saravanaeswari22/the-revolutionize-your-styling-with-stitches-99e8e4ab0825?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/99e8e4ab0825</guid>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[stitches]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[css-library]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 06:29:56 GMT</pubDate>
            <atom:updated>2023-04-02T06:32:03.856Z</atom:updated>
            <content:encoded><![CDATA[<p>CSS (Cascading Style Sheets) is a fundamental language in the front end, and everyone who tried to learn web development has heard about it. While CSS is an essential part of web development, there are several drawbacks to using plain CSS that can make it challenging to create and maintain large web applications. Other CSS libraries may provide some solutions to these limitations, but they can also have their own drawbacks and limitations.</p><p>In this article, we are going to see how Stitches help these problems and provide a more flexible and maintainable way to style web applications.</p><h3>What are stitches?</h3><blockquote>CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.</blockquote><p>Stitches is a modern CSS-in-JS library that allows developers to write CSS in directly JavaScript. It provides a powerful and flexible way to style web applications and components. Here, we will explore the basic of Stitches and provide examples and explanations of how to use them in our project.</p><p>Before jumping into examples, let’s see what are the key features of Stitches and performance.</p><h3>Performance</h3><ul><li><strong>Near-Zero Runtime: </strong>Stitches generate optimized CSS code only for styles that are actually used by the application, resulting in faster load times and improved performance.</li><li><strong>Server-Side Rendering: </strong>Many UI libraries document that responsive variants don’t work with server-side rendering. Since popular frameworks like Next.js and Gatsby have begun prioritizing SSR, we wanted a solution that works well. Stitches support cross-browser server-side rendering, even for responsive styles and variants.</li></ul><h3>Key Features</h3><ul><li><strong>Variants: V</strong>ariants are key features in Stitches that allow developers to create a dynamic style based on the state of an element. There are some features of Variants like Customizable Variants, predefined Variants, Responsive Variants, Multiple Variants, and Scoped Variants.</li></ul><figure><img alt="This is an example for add variants in the button component." src="https://cdn-images-1.medium.com/max/1024/1*aHV0pJxf24DSIg75bLlkvQ.png" /></figure><ul><li><strong>Token: </strong>One of the most exciting features is the ability to define your own tokens and seamlessly apply them as CSS values. CSS Properties are automatically mapped to token scales. Tokens can even be used in shorthand CSS properties.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GXogRYhMrBErRFTn-Bbzdg.png" /></figure><ul><li><strong>Theming: </strong>Stitches provides a simple theming experience out of the box. Create as many themes as you need, and apply them wherever you want. Each theme generates a CSS class name that overrides the default tokens.</li></ul><figure><img alt="This is an example for theming options in stitches" src="https://cdn-images-1.medium.com/max/1024/1*yZBpVJYOc6oEZ-5EXd6JYQ.png" /></figure><ul><li><strong>Utils: </strong>Utile<strong> </strong>allows you to create your own custom CSS Properties, with your own API. Use utils to create powerful combinations of properties, and property aliases and to introduce restrictions when needed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OykawI0IjUi-Dw2HIeqQbA.png" /></figure><ul><li><strong>Responsive Variants: </strong>Stitches let you configure breakpoints and apply variants responsively using the <strong>CSS</strong> prop. CSS at-rules can also be used inline if needed.</li></ul><figure><img alt="This is an example of BreakingPoint" src="https://cdn-images-1.medium.com/max/1024/1*9THcCAJE-wL2HwNJFRd-9w.png" /></figure><ul><li><strong>Overrides: </strong>Stitches provide a <strong>CSS</strong> prop for overriding styles on any Stitches component. You can use this prop to define layout concerns and/or overrides. Tokens and breakpoints also work in the <strong>CSS</strong> prop. Stitches also provide a polymorphic<strong> as</strong> a prop for defining which tag a component renders.</li></ul><figure><img alt="This is an example for Overrides" src="https://cdn-images-1.medium.com/max/1024/1*TbaRTsr8kMnUEysuI1XVQg.png" /></figure><ul><li><strong>Developer Experience: </strong>Stitches provides a fully-typed API, so when using TypeScript, CSS properties, values, and breakpoints will be auto-completed for you. Also, when using the <strong>as</strong> a prop, the prop suggestions will update.</li></ul><p><strong>So let’s dive into Realtime examples!</strong></p><p>If we want to use Stitches, we’ll be installing it by using:</p><pre>npm install @stitches/react</pre><p>Next, we create a config file called stitches.config.js. I created my file right in the src directory, then we have to import the library at the top. Note that we’re importing a function called <strong>createStitches</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VwWYzEK4iX8gARVjiszO_Q.png" /></figure><p>This function accepts one argument, though the argument is an object with five possible keys:</p><ul><li>theme: Define your design theme, which map to CSS properties.</li><li>media: Define reusable responsive breakpoint.</li><li>utils: Create custom utils to improve your developer experience.</li><li>prefix: Prefix class names and CSS variables to avoid clashes.</li><li>themeMap: Define custom mapping of CSS properties to theme tokens.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pdfTB9CQ8gWKc-iEcFI1Tg.png" /></figure><p>Now, we’re exporting the functions, which are called <em>styled</em> and <em>css</em>. Styled will allow us to create a component with custom styling. I created a file called Button.js, imported my new functions, and designed a stylish button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xT5bcSprFDbMRN1wgoQk2A.png" /></figure><p>One of the first things that jumped out at me while I was writing is that Stitches requires all values to be strings, while plain CSS does not.</p><p>The styled function accepts two arguments: the first is an html tag (button, div, li, etc) and the second is an object with CSS properties and values. I imported the Button component into App.js and replaced my plain old ‘button’ element; get a load of that button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qE04iJc45QdtLda_J0Of-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QyzTA-T1cmCvFWjGXzypPQ.png" /></figure><h4>Conclusion:</h4><p>Ever library has its own strength and weaknesses and the best choice for you project will depend on your specific requirements and preference. However, Stitches is a powerful and flexible option that is worth considering for your upcoming projects.</p><p>I hope you find this article helpful for Stitches.</p><h4>Suggestions and criticisms are highly appreciated ❤️</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99e8e4ab0825" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Frontend Architecture]]></title>
            <link>https://medium.com/@saravanaeswari22/micro-frontend-architecture-ee77a3a8f58?source=rss-b66a5bd80e49------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee77a3a8f58</guid>
            <category><![CDATA[micro-front-end]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Saravana]]></dc:creator>
            <pubDate>Sat, 04 Mar 2023 13:08:00 GMT</pubDate>
            <atom:updated>2023-03-04T13:08:00.705Z</atom:updated>
            <content:encoded><![CDATA[<p>Today web applications become increasingly complex, traditional monolithic front-end architectures can pose a range of challenges for developers and organizations, from slow development and deployment cycles to lack of flexibility, scalability, and maintainability. Many companies continue to struggle with monolithic frontend codebases. So that, what we will cover in this article:</p><ul><li>What is micro frontend architecture?</li><li>when should we use micro frontend and why?</li><li>Realtime example</li></ul><p>So let’s dive in!</p><h4>what is micro frontend architecture?</h4><blockquote><em>“An architectural style where independently deliverable frontend applications are composed into a greater whole”</em></blockquote><p>Micro frontends is an architectural style that involves breaking down a web application into smaller, independent, and loosely-coupled components, each of which is developed and deployed independently. In other words, it’s an approach to building front-end applications using multiple smaller applications, rather than one monolithic application.</p><p>It is typically consists of a self-contained, independent user interface (UI) component that is responsible for rendering a specific part of the application’s overall UI. This component can be developed using <strong>different programming languages, frameworks, and technologies, and can be deployed and managed independently of other components.</strong></p><figure><img alt="micro frontend architecture diagram" src="https://cdn-images-1.medium.com/max/1024/1*f5w3vfZzJORsD7bnULW0Cw.png" /></figure><p>In this diagram, we have final one production web app that consists of three micro frontends, each developed using a different front-end framework(react,angular,vue.js).<br>Each micro frontend is responsible for rendering a specific part of the application that overall UI and contains several independent components.</p><p>The components can be developed, deployed and managed independently, which allows for greater flexibility and agility in front end development. <strong>Additionally, each components can be developed different technologies which gives greater freedom to developer to chose the best tool for job.</strong></p><h4>when should we use micro frontend and why 🤔???</h4><p>Micro frontends are typically used in larger and more complex web applications where a monolithic front-end architecture may become difficult to maintain, scale, or update over time. Here are some reasons why organizations may choose to use micro frontends:</p><p><strong>Independent development and deployment:</strong> With micro frontends, different teams can work independently on different parts of the application’s front-end, without needing to coordinate with each other. Each micro frontend can be developed, deployed, and managed independently of other micro frontends, which reduces dependencies and increases agility.</p><p><strong>Technology flexibility:</strong> Since each micro frontend can be developed using a different technology stack, developers have the freedom to choose the best technology for each specific use case, without being limited to a single technology stack for the entire application.</p><p><strong>Scalability:</strong> Micro frontends can be scaled horizontally by replicating individual micro frontends, allowing applications to handle more traffic and users as the demand grows.</p><p><strong>Better maintainability:</strong> Micro frontends allow for better maintainability since each micro frontend is small, focused, and contains only the necessary code for a specific part of the application. This makes it easier to update, fix, or replace individual micro frontends without affecting other parts of the application.</p><p>Overall, micro frontends are a great solution for complex web applications that require flexibility, scalability, and maintainability.</p><h4>Take a break 🏖</h4><p>So far so good — take a break! then drive into real time example.</p><figure><img alt="break image" src="https://cdn-images-1.medium.com/max/1024/1*Zlf9k0jQ2p6DvvloulwkQQ.png" /></figure><h4>Realtime Example:</h4><p>Now we are going to create e-commerce website using micro frontend architecture.</p><figure><img alt="real time example of micro fronetend" src="https://cdn-images-1.medium.com/max/1024/1*Nn_vdWpDlldWTugu57rHBA.png" /></figure><p>Let consider above image and imagine, we have e-commerce website that sell various products. here we used micro frontend how means.</p><p>We will going to break down the website’s UI into several smaller components, such as</p><ul><li>product search component</li><li>product details</li><li>cart</li><li>user accounts like that.</li></ul><p>Here are some steps for using micro frontends in an e-commerce website.</p><p><strong>Choose front-end frameworks:</strong> Choose the front-end frameworks that are best suited for each components area. For example, React may be used for the product search components micro frontend, Angular for the cart micro frontend, and Vue.js for the user accounts micro frontend.</p><p><strong>Develop micro frontends independently:</strong> Each components can be developed independently, using their preferred tools and technologies. Each component should expose a well-defined API that can be used to communicate with other components.</p><p><strong>Integrate micro frontends: </strong>Now, the components are developed, they can be integrated together to create the complete e-commerce website.</p><p>now our e-commerce website ready and greater flexibility, scalability, and maintainability of the front-end architecture. It allows for independent development and deployment of different parts of the website, and provides the ability to choose the best technology for each specific use case. This results in a faster time to market, better user experience, and easier maintenance and updates.</p><h4>Conclusion:</h4><p>In this article you’ve learned:</p><ul><li>what is micro frontend architecture?</li><li>when we should use and why?</li><li>real time example</li></ul><p>I hope you find this article helpful for micro frontend.</p><h4>Suggestions and criticisms are highly appreciated ❤️</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee77a3a8f58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>