<?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 Mohammad Bin Shahed on Medium]]></title>
        <description><![CDATA[Stories by Mohammad Bin Shahed on Medium]]></description>
        <link>https://medium.com/@binshahed?source=rss-17afb1e39e4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ACLEsVrNV4MHygMc3W4H9g.jpeg</url>
            <title>Stories by Mohammad Bin Shahed on Medium</title>
            <link>https://medium.com/@binshahed?source=rss-17afb1e39e4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:05:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@binshahed/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[Modern JavaScript Simplifying Deep Object Cloning]]></title>
            <link>https://medium.com/@binshahed/modern-javascript-simplifying-deep-object-cloning-0143ede7e9fa?source=rss-17afb1e39e4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0143ede7e9fa</guid>
            <category><![CDATA[structuredclone]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[deep-copy]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mohammad Bin Shahed]]></dc:creator>
            <pubDate>Sat, 24 Feb 2024 08:03:41 GMT</pubDate>
            <atom:updated>2024-02-24T08:09:28.028Z</atom:updated>
            <content:encoded><![CDATA[<p>In the dynamic world of JavaScript, working with objects is a common task for developers. However, when it comes to duplicating objects, a simple assignment often falls short. Enter deep cloning, a technique that creates a copy of an object along with all its nested properties and values. In this article, we will explore the intricacies of deep cloning in JavaScript and various approaches to achieve this 🤩.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjMOjIEUy9-92ltDj22o5Q.png" /></figure><h3><strong>Understanding the Need for Deep Cloning:</strong></h3><p>Unlike shallow cloning, which only copies the top-level structure of an object, deep cloning ensures that nested objects and arrays are duplicated as well. This becomes crucial when dealing with complex data structures, preventing unintended references and side effects in your code.</p><p><strong>Let’s consider a common nested object as an example:</strong></p><pre>const originalObject = {<br>  name: &quot;Harry&quot;,<br>  age: 53,<br>  address: {<br>    city: &quot;New York&quot;,<br>    zip: &quot;10001&quot;<br>  }<br>};</pre><blockquote><strong>1: JSON.stringify and JSON.parse</strong></blockquote><p>One straightforward approach to deep cloning an object is by utilizing the JSON.stringify and JSON.parse methods. This method is simple, but it has its limitations, particularly with non-JSON-safe data and functions.</p><pre>const deepCloneJSON = JSON.parse(JSON.stringify(originalObject));</pre><blockquote><strong>2: Utilizing </strong><strong>structuredClone</strong></blockquote><p>The structuredClone() method is a global function in JavaScript designed to create a thorough duplicate of a given value by employing the structured clone algorithm. Additionally, it facilitates the transfer of certain objects within the original value, as opposed to cloning them. Objects designated for transfer are detached from the original object and affixed to the new object, rendering them inaccessible in the original context</p><pre>const deepCloneStructured = structuredClone(originalObject)</pre><blockquote><strong>3: Leveraging External Libraries (Lodash)</strong></blockquote><p>Several external libraries, such as Lodash and Ramda, provide utility functions for deep cloning objects. These libraries often come with additional features, optimizations, and error handling, making them powerful tools for handling complex scenarios.</p><pre>// Using Lodash<br>const _ = require(&#39;lodash&#39;);<br>const deepCloneLodash = _.cloneDeep(originalObject);</pre><p>Deep cloning of objects in JavaScript is a fundamental skill for developers dealing with intricate data structures. Whether you choose the simplicity of JSON.stringify/JSON.parse, the power of external libraries, or the efficiency of structuredClone, understanding the nuances of each method empowers you to make informed decisions based on your project&#39;s requirements. Mastering deep cloning will undoubtedly contribute to cleaner, more maintainable code in your JavaScript projects.</p><p><em>Happy coding…! </em>😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0143ede7e9fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Secrets of JavaScript: Navigating the Call Stack and Memory Heap]]></title>
            <link>https://medium.com/@binshahed/unlocking-the-secrets-of-javascript-navigating-the-call-stack-and-memory-heap-e45da2653600?source=rss-17afb1e39e4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e45da2653600</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[call-stack]]></category>
            <category><![CDATA[heap-memory]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Mohammad Bin Shahed]]></dc:creator>
            <pubDate>Mon, 18 Sep 2023 06:47:40 GMT</pubDate>
            <atom:updated>2023-09-18T06:47:40.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fU00tRex2m2VgvdIRJvZEQ.png" /></figure><p>JavaScript, often referred to as the language of the web, is a versatile and powerful scripting language that plays a crucial role in modern web development. To understand JavaScript at a deeper level, it’s essential to grasp two fundamental concepts: the call stack and the memory heap. In this article, we’ll demystify these two core components of JavaScript and explore how they work together to execute your code efficiently</p><p><strong>The Call Stack</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlJs_uzCVstQfHZ-oPmxzQ.jpeg" /></figure><p>The call stack is a fundamental concept in JavaScript’s execution model. Think of it as a stack of function calls, with the most recently called function at the top. JavaScript is single-threaded, meaning it can execute only one operation at a time. The call stack is the mechanism that manages the execution of these operations.</p><p>When a JavaScript program starts, the main function is pushed onto the call stack. As your code encounters function calls, they are added to the top of the stack, and when a function completes its execution, it is removed from the stack. This process is known as the “Last In, First Out” (LIFO) principle.</p><p>Let’s look at an example to illustrate how the call stack works:</p><pre>function greet(name) {<br>  console.log(`Hello, ${name}!`);<br>}<br><br>function welcome() {<br>  greet(&quot;Alice&quot;);<br>  greet(&quot;Bob&quot;);<br>}<br><br>welcome();</pre><p>In this example, when welcome() is called, it pushes greet(&quot;Alice&quot;) onto the stack, which in turn pushes console.log() onto the stack, and so on. Once console.log() completes, it is removed from the stack, followed by greet(&quot;Alice&quot;), and finally, welcome(). The call stack is empty again, indicating that the program has finished executing.</p><p><strong>The Memory Heap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSCPdYJgyN_oNRbTsXgy2A.png" /></figure><p>While the call stack manages the execution of JavaScript code, the memory heap is responsible for managing memory allocation. The memory heap is where objects, variables, and data structures are stored during the execution of your program. It’s a region of memory that allows for dynamic allocation and deallocation of memory as needed.</p><p>JavaScript employs a garbage collector to keep track of objects in the memory heap that are no longer reachable or referenced by your code. When an object becomes unreachable, the garbage collector frees up the memory it occupied, helping to prevent memory leaks and keep your application running efficiently.</p><p>Here’s a simplified example of how the memory heap works:</p><pre>function createUser(name, age) {<br>  const user = { name, age };<br>  return user;<br>}<br><br>const newUser = createUser(&quot;Eve&quot;, 25);</pre><p>In this code, newUser is assigned the object created by the createUser function. This object is allocated memory in the heap. When newUser goes out of scope or is no longer referenced, the garbage collector identifies it as unreachable and reclaims the memory, ensuring efficient memory usage.</p><p>Interaction between the Call Stack and Memory Heap</p><p>Understanding how the call stack and memory heap interact is crucial for writing efficient JavaScript code. When a function is called and needs access to variables or objects, JavaScript looks to the memory heap to access or allocate the required resources.</p><p>Consider this example:</p><pre>function add(a, b) {<br>  return a + b;<br>}<br><br>function calculate() {<br>  const x = 5;<br>  const y = 10;<br>  return add(x, y);<br>}<br><br>const result = calculate();</pre><p>When calculate() calls add(x, y), it needs access to the values of x and y stored in the memory heap. The call stack keeps track of the function calls, while the memory heap stores the necessary data.</p><p>The call stack and memory heap are essential components of JavaScript’s runtime environment. Understanding how they work together is crucial for writing efficient and bug-free JavaScript code. By grasping the concepts of the call stack’s function execution order and the memory heap’s memory management, you can become a more proficient JavaScript developer and build robust web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e45da2653600" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Visual Elegance, A Deep Dive into Styled Components for React Styling]]></title>
            <link>https://medium.com/@binshahed/mastering-visual-elegance-a-deep-dive-into-styled-components-for-react-styling-fd61d6dbb6f6?source=rss-17afb1e39e4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd61d6dbb6f6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[style-tips]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[styled-components]]></category>
            <dc:creator><![CDATA[Mohammad Bin Shahed]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 12:33:49 GMT</pubDate>
            <atom:updated>2023-08-08T12:33:49.487Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Styled Components" src="https://cdn-images-1.medium.com/max/1024/1*dawpLxsrS9IG6p63oum3yg.jpeg" /></figure><p>In the realm of modern web development, styling is a critical aspect of creating engaging and user-friendly interfaces. With the emergence of CSS-in-JS libraries like Styled Components, developers have gained a powerful tool for seamlessly integrating styling within React applications. This article takes an in-depth exploration of Styled Components, shedding light on its features, benefits, and practical implementation, and how it can revolutionize the way you approach styling in React projects.</p><h3>Understanding Styled Components:</h3><p>Styled Components is a widely adopted CSS-in-JS library that enables developers to write CSS code directly within their JavaScript components. By leveraging the power of template literals, Styled Components allows for the creation of dynamic and scoped styles. Here are the primary advantages that make Styled Components stand out:</p><h3>Scoped Styles for Enhanced Isolation:</h3><p>One of the core benefits of Styled Components is the encapsulation of styles within the components they are associated with. Each Styled Component generates a unique class name, ensuring that styles are isolated and do not collide with other components. This scoped approach eliminates the potential for unintended style clashes and greatly improves the maintainability of your codebase.</p><h3>Dynamic Theming Made Simple:</h3><p>Theming is a crucial aspect of design consistency across an application. Styled Components makes theming effortless through its integration with React’s Context API. By creating a ThemeProvider at the top level of your application, you can supply theme variables throughout the component tree. This enables the dynamic application of themes and maintains a coherent design language across your app.</p><h3>Readable and Maintainable Code:</h3><p>Styled Components bring styles closer to the components they style, enhancing the readability and maintainability of your codebase. No more juggling between separate CSS files or deciphering complex class names. Each Styled Component clearly outlines its styles, making it easier to identify, update, and manage styles as your application evolves.</p><h3>Getting Started with Styled Components:</h3><p>Implementing Styled Components in your React application involves a straightforward process:</p><ol><li><strong>Installation:</strong></li></ol><p>Begin by installing Styled Components using npm or yarn:</p><pre>npm install styled-components</pre><p><strong>2. Creating Styled Components:</strong></p><p>To create a Styled Component, import the styled function from the library and define your styles within a tagged template literal. For instance, let&#39;s style a button component:</p><pre>import styled from &#39;styled-components&#39;;<br><br>const Button = styled.button`<br>  background-color: #3498db;<br>  color: white;<br>  padding: 10px 20px;<br>  border: none;<br>  border-radius: 5px;<br>`;</pre><p><strong>3. Using Styled Components:</strong></p><p>Incorporating the Button Styled Component into your JSX is as simple as using any regular React component:</p><pre>&lt;Button&gt;Click me&lt;/Button&gt;</pre><h3>Advanced Features of Styled Components:</h3><p>Styled Components offer a range of advanced features that further elevate your styling capabilities:</p><ul><li><strong>Dynamic Styles Using Props:</strong> Styled Components can receive props, enabling you to apply styles conditionally based on component props. This feature is invaluable for creating versatile and reusable components.</li><li><strong>Global Styles with </strong><strong>createGlobalStyle:</strong> Styled Components provide a createGlobalStyle utility that allows you to define global styles for your entire application, ensuring consistency across different components.</li></ul><p><em>Styled Components usher in a new era of elegance and efficiency in styling React applications. Their seamless integration with JavaScript, dynamic theming capabilities, and enhanced maintainability make them an indispensable tool for developers. By embracing CSS-in-JS practices with Styled Components, developers can create organized, scalable, and visually captivating applications. Take the plunge, experiment, and witness the transformation of your React projects’ styling workflow. Happy styling, and remember that the possibilities with Styled Components are endless; there’s always more to explore and learn.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd61d6dbb6f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unraveling the JavaScript Event Loop: Demystifying Asynchronous Programming.]]></title>
            <link>https://medium.com/@binshahed/unraveling-the-javascript-event-loop-demystifying-asynchronous-programming-99964990995a?source=rss-17afb1e39e4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/99964990995a</guid>
            <category><![CDATA[event-loop]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[settimeout]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mohammad Bin Shahed]]></dc:creator>
            <pubDate>Tue, 25 Jul 2023 12:07:41 GMT</pubDate>
            <atom:updated>2023-07-25T12:07:41.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UofsqHGLEg8fvmHsebJwlw.png" /></figure><p>As JavaScript developers, we often encounter asynchronous operations that can potentially slow down our applications. Enter the JavaScript Event Loop — a crucial mechanism that allows us to handle these tasks efficiently without compromising responsiveness. In this article, we’ll dive into the world of the event loop, unravel its inner workings, and explore some short examples to solidify our understanding of this fundamental concept in JavaScript.</p><p><strong>Understanding the Event Loop:</strong></p><p>In JavaScript, the event loop is the backbone of asynchronous programming. It manages the execution of code by keeping track of tasks in two critical components: the call stack and the message queue. The call stack is a last-in-first-out (LIFO) data structure that records the execution context of functions. The message queue, on the other hand, stores callbacks from asynchronous tasks.</p><p><strong>Short Example: setTimeout</strong></p><p>Let’s start with a classic example using setTimeout. Imagine we want to display two messages on the console, one immediately and another after a 2-second delay:</p><pre>console.log(&quot;Hello, &quot;);<br>setTimeout(() =&gt; {<br>  console.log(&quot;world!&quot;);<br>}, 2000);<br>console.log(&quot;Welcome to the event loop!&quot;);</pre><p>Output:</p><pre>Hello,<br>Welcome to the event loop!<br>world!</pre><p>In this example, the first console.log is executed immediately and logs &quot;Hello, &quot; to the console. Then, setTimeout is called, which schedules the anonymous callback function to execute after a 2-second delay.</p><p>While waiting for the 2 seconds to pass, the JavaScript engine doesn’t sit idle. Instead, it continues executing the remaining code. The last console.log statement is executed right away, printing &quot;Welcome to the event loop!&quot; to the console.</p><p>Once the 2 seconds elapse, the anonymous callback function is moved from the message queue to the call stack and executed. As a result, “world!” is logged to the console.</p><p><strong>Short Example: AJAX Request</strong></p><p>Next, let’s consider an AJAX request using XMLHttpRequest to fetch data from an API:</p><pre>console.log(&quot;Fetching data...&quot;);<br>const xhr = new XMLHttpRequest();<br>xhr.open(&quot;GET&quot;, &quot;https://api.example.com/data&quot;);<br>xhr.onload = () =&gt; {<br>  console.log(&quot;Data retrieved:&quot;, xhr.responseText);<br>};<br>xhr.send();<br>console.log(&quot;Continuing execution...&quot;);</pre><p>Output:</p><pre>Fetching data...<br>Continuing execution...<br>Data retrieved: { &quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 30 }</pre><p>In this example, we initiate the AJAX request to fetch data from the API. The first console.log statement logs &quot;Fetching data...&quot; to the console. Just like before, the JavaScript engine continues execution without waiting for the response.</p><p>Once the response is received, the onload event handler is triggered. The callback function logs &quot;Data retrieved: { &quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 30 }&quot; to the console, displaying the fetched data.</p><p><strong>Short Example: Promise</strong></p><p>Promises provide an elegant way to handle asynchronous operations and further showcase the event loop’s power:</p><pre>function fetchData() {<br>  return new Promise((resolve, reject) =&gt; {<br>    setTimeout(() =&gt; {<br>      resolve(&quot;Data retrieved successfully!&quot;);<br>    }, 1500);<br>  });<br>}<br><br>console.log(&quot;Fetching data...&quot;);<br>fetchData().then((result) =&gt; {<br>  console.log(result);<br>});<br>console.log(&quot;Continuing execution...&quot;);</pre><p>Output:</p><pre>Fetching data...<br>Continuing execution...<br>Data retrieved successfully!</pre><p>In this example, we define a fetchData() function that returns a Promise. The Promise resolves after a 1.5-second delay with the message &quot;Data retrieved successfully!&quot;</p><p>When we call fetchData(), the initial &quot;Fetching data...&quot; message is logged. The event loop then proceeds with execution and logs &quot;Continuing execution...&quot; without waiting for the Promise to resolve.</p><p>Once the 1.5 seconds pass, the resolved value of the Promise is moved to the message queue and then to the call stack. The .then() callback is executed, and &quot;Data retrieved successfully!&quot; is printed to the console.</p><p>Understanding the JavaScript event loop is vital for writing efficient and responsive code. By grasping how the call stack and message queue interact, we can better handle asynchronous operations without blocking the main thread. Armed with this knowledge, we can create highly performant applications that provide delightful user experiences. Embrace the power of asynchronous programming and let the event loop be your ally in building exceptional JavaScript applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99964990995a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>