<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md Pervez Hossain</title>
    <description>The latest articles on DEV Community by Md Pervez Hossain (@pervez).</description>
    <link>https://dev.to/pervez</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1500289%2F0fab1bd4-b440-4720-88b0-530293be377d.jpg</url>
      <title>DEV Community: Md Pervez Hossain</title>
      <link>https://dev.to/pervez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pervez"/>
    <language>en</language>
    <item>
      <title>Event Loop in JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Tue, 29 Apr 2025 06:42:48 +0000</pubDate>
      <link>https://dev.to/pervez/event-loop-in-javascript-3bak</link>
      <guid>https://dev.to/pervez/event-loop-in-javascript-3bak</guid>
      <description>&lt;p&gt;&lt;strong&gt;🚀 Mastering JavaScript Event Loop — Simplified for Interviews&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↔️  In JavaScript, everything starts with the Call Stack- a synchronous structure (Code Executes LIFO order ).&lt;/p&gt;

&lt;p&gt;Because JavaScript is single-threaded, it leans on Browser Web APIs (like setTimeout, fetch, DOM APIs) to handle async operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Browser Superpowers (Web APIs)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Browsers provide extra features beyond the JavaScript engine, called Web &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;APIs, including :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setTimeout, setInterval&lt;/li&gt;
&lt;li&gt;DOM Manipulation APIs&lt;/li&gt;
&lt;li&gt;fetch (for network requests)&lt;/li&gt;
&lt;li&gt;localStorage&lt;/li&gt;
&lt;li&gt;console&lt;/li&gt;
&lt;li&gt;location&lt;/li&gt;
&lt;li&gt;Bluetooth access, Geolocation, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These features are accessible via the window object in browsers.&lt;/p&gt;

&lt;p&gt;When an asynchronous operation (like setTimeout or fetch) is triggered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; It is registered in the Web API Environment provided by the browser.&lt;/li&gt;
&lt;li&gt; Once completed (like a timer expiring or a network request finishing), the corresponding callback is placed into queues — waiting for the Call Stack to be free.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🔥 Event Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Event Loop continuously monitors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the Call Stack is empty.&lt;/li&gt;
&lt;li&gt;If there are pending callbacks in the Queues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Its main job:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the Call Stack is empty, the event loop moves queued callback functions to the Call Stack for execution. Callback functions in the Microtask Queue are given priority and executed first Then Callback (Task) Queue.&lt;/p&gt;

&lt;p&gt;🧩 Microtask Queue vs Callback (Task) Queue&lt;/p&gt;

&lt;p&gt;There are two important types of queues:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Microtask Queue:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher priority than the Callback Queue.&lt;/li&gt;
&lt;li&gt;Promise .then() / .catch() / .finally() handlers call back functions and  MutationObserver callbacks  function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Callback Queue (Task Queue) :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lower priority.&lt;/li&gt;
&lt;li&gt;Includes:&lt;/li&gt;
&lt;li&gt;setTimeout , setInterval , UI rendering callbacks , DOM event callbacks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before picking a task from the Callback Queue, the Event Loop empties all microtasks first.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>eventloop</category>
    </item>
    <item>
      <title>Hydration Process In React</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Wed, 23 Apr 2025 07:44:52 +0000</pubDate>
      <link>https://dev.to/pervez/hydration-process-in-react-46ac</link>
      <guid>https://dev.to/pervez/hydration-process-in-react-46ac</guid>
      <description>&lt;p&gt;&lt;strong&gt;🚀 React এ Hydration কী?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;আমরা জানি, React মূলত একটি client-side library। কিন্তু Server-Side Rendering (SSR) এর মাধ্যমে আমরা React কম্পোনেন্টগুলো server এ রেন্ডার করে client এ static HTML পাঠাতে পারি। কিন্তু প্রশ্ন হচ্ছে:&lt;br&gt;
React সেই static HTML কে interactive কিভাবে বানায়? 🤔&lt;br&gt;
এটাই হলো Hydration!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌊 Hydration কি?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hydration হলো সেই প্রক্রিয়া, যেখানে server-rendered static HTML কে client-side এ interactive বানানো হয়, React এর মাধ্যমে। React event listeners এবং state যুক্ত করে এই HTML কে পুরোপুরি interactive করে তোলে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;কীভাবে কাজ করে?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server Render:&lt;/strong&gt; Server React কম্পোনেন্টগুলোকে HTML তে রেন্ডার করে এবং ব্রাউজারে পাঠায়।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initial Load:&lt;/strong&gt; ব্রাউজার সেই static HTML রিসিভ করে (এখনো React functionality নেই)।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hydration:&lt;/strong&gt; React ব্রাউজারে লোড হয়ে সেই HTML কে "hydrate" করে, ইভেন্ট লিসেনার এবং স্টেট যুক্ত করে।&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactivity:&lt;/strong&gt; এখন HTML পুরোপুরি interactive হয়ে ওঠে — বাটন ক্লিক করা, state পরিবর্তন হওয়া, React এর magic চলে আসে! 🎩✨&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 Hydration কেন প্রয়োজন?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Hydration নিশ্চিত করে যে : *&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Static HTML যা server থেকে এসেছে, সেটি interactive হয়ে ওঠে ব্রাউজারে।&lt;/li&gt;
&lt;li&gt;React তার Virtual DOM কে server-rendered HTML এর সাথে মিলিয়ে client-side React app কে কার্যকরী করে তোলে। &lt;/li&gt;
&lt;li&gt;Hydration ছাড়া, তোমার পেজ static থাকবে, যেখানে ইউজার কোনো interactivity উপভোগ করতে পারবে না (যেমন, বাটনে ক্লিক করা, ফর্মে টাইপ করা, বা UI আপডেট হওয়া যাবে না)।&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🔥 Hydration প্রক্রিয়া কীভাবে কাজ করে?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initial Render: Server HTML রেন্ডার করে → ব্রাউজার static কন্টেন্ট পায়।&lt;/li&gt;
&lt;li&gt;Hydration: React ইভেন্ট লিসেনার এবং স্টেট যুক্ত করে।&lt;/li&gt;
&lt;li&gt;State Changes: React state এর পরিবর্তন অনুযায়ী UI আপডেট করে, যা dynamic interactivity দেয়।&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;⚠️ Hydration Error কখন হয়?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hydration error তখন ঘটে যখন server-generated HTML এবং client-rendered HTML এর মধ্যে ম্যাচ না করে।&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;যেমন: যদি তুমি Math.random() ব্যবহার করো, তাহলে server-এ যে ভ্যালু তৈরি হবে তা client-এ তৈরি হওয়া ভ্যালুর সাথে মেলাবে না।&lt;/li&gt;
&lt;li&gt;এই mismatch এর কারণে hydration error হয়, কারণ React আশা করে যে, server-rendered এবং client-rendered HTML এক হতে হবে।&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🚀 Hydration প্রক্রিয়া: গুরুত্বপূর্ণ টিপস&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hydration শুধুমাত্র client-side প্রক্রিয়া, যা প্রথম রেন্ডার হওয়ার পর ঘটে।&lt;/li&gt;
&lt;li&gt;React event listeners, state যোগ করে এবং অ্যাপটিকে interactive করে তোলে।&lt;/li&gt;
&lt;li&gt;Hydration error তখন ঘটে, যখন server-generated HTML এবং client-rendered HTML এর মধ্যে mismatch হয়।&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔍 &lt;strong&gt;সংক্ষেপে:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hydration হলো server-rendered static HTML কে dynamic, interactive React app এ পরিণত করার প্রক্রিয়া। এটা বুঝলে তুমি SSR (Server-Side Rendering) অ্যাপ্লিকেশনগুলোকে আরও ভালভাবে অপটিমাইজ করতে পারবে। 🚀&lt;/p&gt;

</description>
      <category>programming</category>
      <category>react</category>
      <category>nextjs</category>
      <category>hydration</category>
    </item>
    <item>
      <title>Promise of JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Sat, 26 Oct 2024 16:08:18 +0000</pubDate>
      <link>https://dev.to/pervez/promise-of-javascript-34in</link>
      <guid>https://dev.to/pervez/promise-of-javascript-34in</guid>
      <description>&lt;p&gt;Before the promise we use callBack function  for asynchronous Task. which has two Major Issue &lt;/p&gt;

&lt;p&gt;1.) Callback Hell (Pyramid of doom) &lt;br&gt;
2.) Inversion of control&lt;/p&gt;

&lt;p&gt;Inversion of control is overcome by using promise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the Promise ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A promise is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It Has Three States 🎉&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Pending State :&lt;/strong&gt; The initial state, neither fulfilled nor rejected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Fulfilled State  :&lt;/strong&gt; Operation Completed Successfully&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Rejected State :&lt;/strong&gt; Operation rejected&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍 :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In a promise, we do not pass a function directly; instead, we attach a callback function to the promise. When the promise is settled, JavaScript guarantees that the callback function will be called automatically exactly once.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As soon as the promise is fulfilled/rejected , It updates the empty object which is assigned undefined in the pending state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A promise resolves only once and it is immutable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A promise provides a method, .then(), to handle the result of the asynchronous operation once it is settled. (fulfilled or rejected)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To avoid callback hell (Pyramid of doom) , We use promise chaining. This way our code expands vertically instead of horizontally. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;.then() Method is used For Promises Chaining&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In promise chaining, always use the return statement to pass a value from one promise to the next.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Promises provide a way to handle asynchronous tasks, allowing for more readable and maintainable code when dealing with operations that take time to complete, such as network requests, file reading, or database queries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise Api&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.all() API 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.all() is a powerful method in JavaScript that allows you to handle multiple promises at the same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes an Iterable Object: Promise.all takes iterable promises ( such as an array ) and returns a single promise.&lt;/li&gt;
&lt;li&gt;Resolves Together: The returned promise resolves when all promises in the array have resolved.&lt;/li&gt;
&lt;li&gt;Results Array: The resolved value is an array of results, in the same order as the original promises.&lt;/li&gt;
&lt;li&gt;Error Handling: If any promise rejects, Promise.all immediately rejects with that error, and it won't wait for other promises to finish.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxdnveb61wslj6o5rk9x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwxdnveb61wslj6o5rk9x.png" alt="Image description" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.allSettled() API 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes an Iterable Object: Promise.allSettled takes an iterable object (such as an array) and returns a single promise.&lt;/li&gt;
&lt;li&gt;Settles Together: The returned promise settles (resolves or rejects) when all promises in the iterable have settled (either resolved or rejected).&lt;/li&gt;
&lt;li&gt;Results Array: The settled value is an array of result objects, in the same order as the original promises:&lt;/li&gt;
&lt;li&gt;Each Settled result object contains a status property : &lt;/li&gt;
&lt;li&gt;status: "fulfilled" if the promise was successfully resolved, along with a value property containing the resolved value.&lt;/li&gt;
&lt;li&gt;status: "rejected" if the promise was rejected, along with a reason property containing the rejection reason.&lt;/li&gt;
&lt;li&gt;No Interruption:  Promise.allSettled waits for all promises to settle (resolve or reject).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Promise.race() API 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.race() is a powerful method in JavaScript that allows you to handle multiple promises. It is crucial for scenarios where you need to act on the first settled (resolved or rejected) promise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Promise.race takes iterable promises ( such as an    array ) .&lt;/li&gt;
&lt;li&gt;It returns a single promise with First Settled (resolve or reject ) promise with  the   First resolved value or the First reason of rejection. &lt;/li&gt;
&lt;li&gt;it does not wait for the other promises to settle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnux5mdh1wyrmpteggxcp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnux5mdh1wyrmpteggxcp.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.any() API 👍&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.any() is a powerful method in JavaScript that allows you to handle multiple promises. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Promise.any() takes iterable promises ( such as an    array ) .&lt;/li&gt;
&lt;li&gt;It returns a single promise with First Resolved ( success ) promise with  the value &lt;/li&gt;
&lt;li&gt;It does wait for promises to resolve but resolves as soon as one of them resolves. It does not wait for all promises to resolve or reject before returning.&lt;/li&gt;
&lt;li&gt;If all promises in the iterable are rejected (none of them resolve successfully), Promise.any() returns a AggregateError which contains an array of all the rejection reasons from the original iterable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipbbcje4232mlt8w6tez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipbbcje4232mlt8w6tez.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>call() , apply() and bind() Method In JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Fri, 25 Oct 2024 20:17:29 +0000</pubDate>
      <link>https://dev.to/pervez/call-apply-and-bind-method-in-javascript-2n7</link>
      <guid>https://dev.to/pervez/call-apply-and-bind-method-in-javascript-2n7</guid>
      <description>&lt;h2&gt;
  
  
  What is the call() Method in js ?
&lt;/h2&gt;

&lt;p&gt;call() method is a built-in javascript method that allows us to invoke a function with specified “this” context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First parameter Sets “this” context value for the function.&lt;/li&gt;
&lt;li&gt;Make a function Reusable.&lt;/li&gt;
&lt;li&gt;Apply the same function to different objects.&lt;/li&gt;
&lt;li&gt;Others parameter  passed with comma seperated&lt;/li&gt;
&lt;li&gt;It calls the function directly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpi0bytjks8zxgdwzz8y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpi0bytjks8zxgdwzz8y7.png" alt="Image description" width="800" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the apply() Method in js ?
&lt;/h2&gt;

&lt;p&gt;apply() method is a built-in javascript method that allows us to invoke a function with specified “this” context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First parameter Sets “this” context value for the function.&lt;/li&gt;
&lt;li&gt;Make a function Reusable.&lt;/li&gt;
&lt;li&gt;Apply the same function to different objects.&lt;/li&gt;
&lt;li&gt;Other parameters are passed as an array:&lt;/li&gt;
&lt;li&gt;It calls the function Immediately&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0zb9zsh7zgr8ljznn5km.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0zb9zsh7zgr8ljznn5km.png" alt="Image description" width="800" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the bind() Method in js ?
&lt;/h2&gt;

&lt;p&gt;The bind() method is a built-in JavaScript method that creates a copy of the original function and returns a new function with a specified this context, rather than invoking the original function immediately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features 👍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First parameter Sets “this” context value for the function.&lt;/li&gt;
&lt;li&gt;Make a function Reusable.&lt;/li&gt;
&lt;li&gt;Apply the same function to different objects.&lt;/li&gt;
&lt;li&gt;Others parameter  passed with comma seperated&lt;/li&gt;
&lt;li&gt;creates a copy of the original function and returns a new function &lt;/li&gt;
&lt;li&gt;Need to call the returned function to access the original functionality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fem35c7h7uoh9qffug3dw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fem35c7h7uoh9qffug3dw.png" alt="Image description" width="800" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Differences between call() , apply() and bind() Methods :
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Execution Timing:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;call() and apply() invoke the function immediately.&lt;/li&gt;
&lt;li&gt;bind() returns a new function without invoking it, allowing deferred execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Arguments Handling:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;call() accepts arguments as comma-separated values.&lt;/li&gt;
&lt;li&gt;apply() requires arguments as an array.&lt;/li&gt;
&lt;li&gt;bind() also uses comma-separated arguments, but these are pre-set for later when the function is invoked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Return Value:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;call() and apply() return the result of the function call.&lt;/li&gt;
&lt;li&gt;bind() returns a new function with the specified this context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Write down in the comment box your knowledge about the call(), apply(), and bind() methods.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Node.js Module System and require Function</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Tue, 15 Oct 2024 19:48:53 +0000</pubDate>
      <link>https://dev.to/pervez/nodejs-module-system-and-require-function-5i1</link>
      <guid>https://dev.to/pervez/nodejs-module-system-and-require-function-5i1</guid>
      <description>&lt;h2&gt;
  
  
  Global Objects in Node.js vs Browsers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In browsers, the global object is window.&lt;/li&gt;
&lt;li&gt;In Node.js, the global object is global.&lt;/li&gt;
&lt;li&gt;However, this in the global scope of a Node.js module points to module.exports, not global.&lt;/li&gt;
&lt;li&gt;this keyword is an empty object ({}) in node js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Entry Point:&lt;/strong&gt; Every Node.js project has a main file (e.g., index.js or app.js) that starts the application, setting up the environment and logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Node.js Modules Overview
&lt;/h2&gt;

&lt;p&gt;In Node.js, modules help organize and encapsulate code. A module is simply a file containing JavaScript code that can be imported or exported using CommonJS or ESM systems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Files as Modules:&lt;/strong&gt; Each file in Node.js is a module with its own scope.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of Modules:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Core Modules:&lt;/strong&gt; Built-in, no installation needed (const fs = require('fs');).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Third-Party Modules:&lt;/strong&gt; Installed via npm (const express = require('express');).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Modules:&lt;/strong&gt; Use relative paths (const myModule = require('./myModule');).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Modules Key Points:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every file is a module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;require() Function:&lt;/strong&gt; Used to import modules, loaded synchronously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;module.exports:&lt;/strong&gt; Used to export functionality from a module.&lt;/li&gt;
&lt;li&gt;Core and third-party modules don't need paths, but local modules do.&lt;/li&gt;
&lt;li&gt;Modules protect their variables,functions,objects,and arrays from leaking by default unless exported. &lt;/li&gt;
&lt;li&gt;variables,functions,objects,and arrays etc are scoped to their local module&lt;/li&gt;
&lt;li&gt;When you export more than one, you need to wrap it into an object&lt;/li&gt;
&lt;li&gt;In Node.js, this in the global scope refers to an empty object, while this inside a module refers to module.exports.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In JavaScript, a module is simply a file that contains code you want to use in other parts of your program. Modules help organize and encapsulate functionality, making your code more maintainable, reusable, and easier to manage .&lt;/p&gt;

&lt;h2&gt;
  
  
  There Two types of Module :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Common Js Module 👍&lt;/li&gt;
&lt;li&gt;Es Module 👍&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Js Module 👍
&lt;/h2&gt;

&lt;p&gt;CommonJS is a module system used in Node.js to allow modular code by defining how to import and export modules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses require() to import and module.exports to export.&lt;/li&gt;
&lt;li&gt;Synchronous loading of modules.&lt;/li&gt;
&lt;li&gt;Works in non-strict mode. ( Example: You can declare variables without var, let, or const, but it’s bad practice.)&lt;/li&gt;
&lt;li&gt;IIFE (Immediately Invoked Function Expression) wraps modules for local scope.&lt;/li&gt;
&lt;li&gt;Still widely used in Node.js, though ESM is preferred for new projects.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CommonJS allows you to break your code into reusable modules, making it more organized and maintainable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;default module system in older Node.js versions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Useful built-in global variables available in every CommonJS module:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;module.exports:&lt;/strong&gt; To define what a module exposes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;require():&lt;/strong&gt; To load another module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;__dirname:&lt;/strong&gt; The directory path of the current module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;__filename:&lt;/strong&gt; The absolute path of the current module file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Es Module 👍
&lt;/h2&gt;

&lt;p&gt;ESM (ECMAScript Modules): This is the standard JavaScript module system, also referred to as ES Modules or MJS (for files with .mjs extension).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses import and export for modular code.&lt;/li&gt;
&lt;li&gt;Standard in frameworks like React, Vue, and Angular.&lt;/li&gt;
&lt;li&gt;Module loading is async, enabling better performance.&lt;/li&gt;
&lt;li&gt;ESM enforces strict mode by default.&lt;/li&gt;
&lt;li&gt;Must use var, let, or const for variable declarations.&lt;/li&gt;
&lt;li&gt;Files use .mjs or "type": "module" in package.json for Node.js.&lt;/li&gt;
&lt;li&gt;ESM supports await at the top level without needing to wrap it in an async function.&lt;/li&gt;
&lt;li&gt;ESM uses import instead of require().&lt;/li&gt;
&lt;li&gt;Supports named exports and default exports for flexibility.&lt;/li&gt;
&lt;li&gt;Once exported, values cannot be re-assigned by the importer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Differences between CommonJS and ESM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CommonJS&lt;/strong&gt; is synchronous and can be used in Node.js without any configuration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ESM&lt;/strong&gt; is the standard in modern JavaScript and works both in the browser and in Node.js with a few extra steps (like setting "type": "module" in package.json or using the .mjs file extension).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Module&lt;/strong&gt;: A reusable block of code (functions, variables, etc.) in a file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Module System&lt;/strong&gt;: The system used to manage, load, and export/import these modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt;: Primarily used the CommonJS module system, but now also supports ESM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Benefits&lt;/strong&gt;: Makes code modular, maintainable, and reusable across large applications.&lt;/li&gt;
&lt;li&gt;In Node.js, module.exports is a special object that is used to export values (such as functions, objects, or variables) from a module, so that they can be imported and used in other files (modules).&lt;/li&gt;
&lt;li&gt;When you write code in Node.js, each file is treated as a separate module. The module.exports object is what defines the public API of that module — meaning whatever you assign to module.exports will be accessible when you require() that module in another file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Node.js require() Function Jobs :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resolving the Module&lt;/strong&gt; – Identifies the location of the module (file path, core module, or node_modules).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loading the Module&lt;/strong&gt; – Reads the content based on its file type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrapping in IIFE&lt;/strong&gt; – Encapsulates the module in a function to provide local scope and access to necessary variables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Evaluation&lt;/strong&gt; – Executes the module's code and returns the module.exports object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching&lt;/strong&gt; – Stores the module in memory for future require() calls to reuse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Node.js does not directly send module code to the V8 engine. Instead, it first takes the module content, wraps it inside an IIFE (Immediately Invoked Function Expression), and then sends this wrapped code to the V8 engine for execution."&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Breakdown:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Module Wrapping:&lt;/strong&gt; Node.js wraps the code of each module in a function (IIFE) to create a private scope and inject variables like exports, require, module, etc.&lt;br&gt;
&lt;strong&gt;Execution in V8:&lt;/strong&gt; After wrapping the module in an IIFE, Node.js sends the wrapped function to the V8 JavaScript engine, where it is parsed and executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is IIFE in JavaScript ❓&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IIFE stands for Immediately Invoked Function Expression. It's a JavaScript function that runs as soon as it is defined.&lt;/li&gt;
&lt;li&gt;An IIFE is created by wrapping a function inside parentheses and This parentheses convert it from a function declaration into a function expression.&lt;/li&gt;
&lt;li&gt;Immediately invoking it with another set of parentheses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Use IIFE ❓&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Global Variable Pollution :&lt;/strong&gt; IIFEs create a local scope, preventing variables from affecting the global scope, avoid naming conflicts and enhancing modularity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulation of Code :&lt;/strong&gt; IIFEs keep the code self-contained and inaccessible from outside, ensuring a cleaner codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private Variables :&lt;/strong&gt; Variables inside an IIFE are private and can't be accessed externally, improving data security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Initialization Code :&lt;/strong&gt; IIFEs are ideal for executing code immediately, especially for one-time setups or initializations .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Node.js, the module system is essential for organizing and encapsulating code. Node.js originally used the CommonJS module system with require() for importing and module.exports for exporting, making code reusable across different files. Now, with the rise of ES Modules (ESM), JavaScript has embraced a modern, standardized system using import and export with async loading and strict mode.&lt;/p&gt;

&lt;p&gt;The primary goal of both systems is to improve maintainability, reusability, and modularity, but ESM is now favored for its performance benefits and alignment with browser-based JavaScript.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Super Power of Node Js</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Sat, 12 Oct 2024 07:40:09 +0000</pubDate>
      <link>https://dev.to/pervez/super-power-of-node-js-5226</link>
      <guid>https://dev.to/pervez/super-power-of-node-js-5226</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is a Server ? 🖥&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A Server is a computer system or Program that provides resources or data to client Computers through a network. Essentially, a server is a machine (like any computer) which is located somewhere .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Every domain name (like google.com) is linked to a unique IP address, which points to the server (a computer or machine) where the website is hosted. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you type a domain name in the browser, it sends a request to that server, which responds by delivering the requested content (e.g., a web page) .&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example : 💡&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;If you set up a web server on your computer and store websites on it, your computer will act as the server. When users type the website's domain name (URL) into their browser, the browser sends a request to your server (your computer). Your server then responds by sending back the requested web pages.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In this case, your computer is functioning as a web server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Javascript is the main Language which is used in the web browser for client site interactive behavior. But after node js you can use javascript on the server.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js is built using JavaScript and  C++ . But End Of the day it's C++ Programe.&lt;/li&gt;
&lt;li&gt;Node.js uses the V8 JavaScript engine, which was developed by Google.&lt;/li&gt;
&lt;li&gt;The V8 engine is a C++ program that executes JavaScript code.&lt;/li&gt;
&lt;li&gt;JavaScript Engine is not a Physical Machine ,  it is a piece of software ( Piece of code ) that executes JavaScript code.&lt;/li&gt;
&lt;li&gt;The V8 engine can be embedded into any C++ application, which has significantly contributed to the creation of Node.js.&lt;/li&gt;
&lt;li&gt;Computers don’t understand JavaScript code directly. We write JavaScript code, and the V8 engine reads and compiles it into machine code that the computer can execute. &lt;/li&gt;
&lt;li&gt;This is why Ryan Dahl wrote Node.js in C++ and utilized the V8 engine for compilation.&lt;/li&gt;
&lt;li&gt;Js Engines Follow  ECMAScript standards.&lt;/li&gt;
&lt;li&gt;ECMAScript (often abbreviated as ES) is a standard for scripting languages. It defines the syntax, semantics, rules and behavior of programming constructs in JavaScript.&lt;/li&gt;
&lt;li&gt;ECMAScript ensures that different JavaScript engines (like V8, SpiderMonkey, and JavaScriptCore) interpret the language in a consistent manner. &lt;/li&gt;
&lt;li&gt;This consistent manner allows developers to write code that works across various platforms and environments.&lt;/li&gt;
&lt;li&gt;V8 cannot connect to databases, can not access the file system, can not perform network calls, or fetch images and resources. &lt;/li&gt;
&lt;li&gt;Its main job is to execute JavaScript code according to the core ECMAScript standard.&lt;/li&gt;
&lt;li&gt;Along With V8 Engine , Node Js also adding its own powerful features.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;JavaScript Runtime Environment :&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Node.js uses the V8 engine to execute JavaScript code, and it adds additional core features such as file system access, database connectivity, and networking.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These features extend the capabilities of JavaScript, creating a runtime environment that allows JavaScript to be used for server-side applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This combination of V8 and Node.js's built-in modules  is known as the JavaScript Runtime Environment in Node.js.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Node.js Super Powers :&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Non-Blocking, Asynchronous I/O:&lt;/strong&gt; One of Node.js’s core strengths is its non-blocking I/O model, which allows it to handle multiple requests at the same time without waiting for one to finish before starting another. This makes Node.js extremely fast and efficient for tasks like file handling and network communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event-Driven Architecture:&lt;/strong&gt; Node.js has an event loop, which processes requests as per events. This architecture allows it to efficiently handle real-time data streams and applications like chat services or live dashboards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Built-in Modules :&lt;/strong&gt;  Node.js provides many built-in modules (such as http, fs, path, etc.) that handle essential server-side functionalities like creating web servers, managing the file system, networking, and more. This allows developers to build powerful server applications quickly without needing external libraries.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;http:&lt;/strong&gt; Used to create web servers and handle HTTP requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fs:&lt;/strong&gt; Used to interact with the file system (read/write files).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;path:&lt;/strong&gt; Used for working with and manipulating file paths in a cross-platform way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Single-Threaded but Scalable:&lt;/strong&gt; Although Node.js operates on a single thread, it can handle multiple operations concurrently due to its event loop and asynchronous nature. This allows Node.js to scale horizontally and handle large volumes of connections efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Platform:&lt;/strong&gt; Node.js runs on various platforms, including Windows, Linux, and macOS. This makes it a versatile solution for different environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full-Stack Development:&lt;/strong&gt; Node.js allows developers to use JavaScript on both the client-side and server-side, enabling full-stack development with a single language&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Streaming Capabilities:&lt;/strong&gt; Node.js is excellent for handling data streaming applications, such as video streaming, file uploads, or real-time data transmission.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In Conclusion&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Node.js is not just another JavaScript runtime. It is a powerful combination of the V8 JavaScript engine and C++-based extensions that provide server-side capabilities. By embedding V8, Node.js can execute JavaScript efficiently, but by adding features like file system access, database connectivity, and networking, it transforms into a full server environment. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Memory Location Behavior in JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Mon, 01 Jul 2024 15:30:17 +0000</pubDate>
      <link>https://dev.to/pervez/memory-location-behavior-in-javascript-4c6c</link>
      <guid>https://dev.to/pervez/memory-location-behavior-in-javascript-4c6c</guid>
      <description>&lt;p&gt;👍 &lt;strong&gt;Primitive Types&lt;/strong&gt;&lt;br&gt;
Primitive types in JavaScript include Number, String, Boolean, Null, Undefined, Symbol, and BigInt. These types are immutable and are stored directly in the variable's memory location.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Memory Behavior :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a primitive value is assigned to a variable, the value itself is stored in the variable's memory location.&lt;/li&gt;
&lt;li&gt;When the variable is assigned to another variable, the value is copied. Changes to one variable do not affect the other.&lt;/li&gt;
&lt;li&gt;When the variable is Re-assigned , the value is stored in the new memory location.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef8qx5iszppceh06h56l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef8qx5iszppceh06h56l.png" alt="Image description" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Explanation , of Above Example&lt;/strong&gt;&lt;/em&gt; : 👇&lt;/p&gt;

&lt;p&gt;The variable "a" is declared and initialized with the value 10. This means a directly stores the value 10 in its memory location.&lt;/p&gt;

&lt;p&gt;The variable "b" is declared and initialized with the value of "a". Since "a" holds a primitive value, "b" gets a copy of that value. At this point, "b" also stores the value 10 in its own memory location. Now, both "a" and "b" have the value 10, but they are stored in separate memory locations.&lt;/p&gt;

&lt;p&gt;Now variable "b" is reassigned with the value 20. This changes the value stored in b's memory location to 20. The variable "a" remains unchanged and still holds the value 10 because hey are stored in separate memory locations.&lt;/p&gt;

&lt;p&gt;👍 &lt;strong&gt;Reference Types&lt;/strong&gt;&lt;br&gt;
Reference types include Object, Array, Function, and other objects created using the new keyword. These types are mutable and are stored as references to their memory locations.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Memory Behavior :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When a reference type value is assigned to a variable, the variable stores a reference (or pointer) to the location in memory where the value is actually stored.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the variable is assigned to another variable, only the reference is copied, not the value itself. Changes to one variable affect the other because they both reference the same object.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7yxpcwu4kidgniv2ec0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7yxpcwu4kidgniv2ec0z.png" alt="Image description" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Explanation , of Above Example&lt;/strong&gt;&lt;/em&gt;  : 👇&lt;/p&gt;

&lt;p&gt;Here "obj1" is a object . In JavaScript Object is Reference Data Types , meaning they are stored in memory, and variables store references (or pointers) to those objects. "obj1" is assigned a reference to an object with a property name set to "Alice".&lt;/p&gt;

&lt;p&gt;"obj2" is assigned the same reference as "obj1". Now, both "obj1" and "obj2" point to the same object in memory.&lt;/p&gt;

&lt;p&gt;Changing the name property of the object through "obj2" also affects "obj1" because both variables reference the same object.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This distinction between primitive values and objects/references is crucial for understanding how variables interact with memory in JavaScript, particularly when using let for variable declarations.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Callback Hell In JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Mon, 10 Jun 2024 09:32:20 +0000</pubDate>
      <link>https://dev.to/pervez/callback-hell-in-javascript-1j83</link>
      <guid>https://dev.to/pervez/callback-hell-in-javascript-1j83</guid>
      <description>&lt;p&gt;&lt;strong&gt;Callback Hell In JavaScript :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✍  When a function is passed as an argument to another function, it becomes a callback function. This process continues and there are many callbacks inside another's Callback function. The code grows  horizontally instead of vertically .That mechanism is known as callback hell.&lt;/p&gt;

&lt;p&gt;Callback Hell (Pyramid of Doom) , occurs in asynchronous programming when multiple callbacks are nested within one another . This pattern emerges when each asynchronous operation requires a callback function, and these callbacks contain further asynchronous operations that also need callbacks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnvzza7u9h9agv2mrr266.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnvzza7u9h9agv2mrr266.png" alt="Image description" width="800" height="771"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✍ Explanation :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;createOrder Function:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the createOrder function is called, a callback function is passed into it.&lt;/li&gt;
&lt;li&gt;Example: createOrder(() =&amp;gt; {}).&lt;/li&gt;
&lt;li&gt;Inside createOrder, this callback function is executed after completing the createOrder operation.&lt;/li&gt;
&lt;li&gt;By using this callback function, you can call paymentOfOrder inside the callback after createOrder is done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fitjmeq5uoor66e7yo1ua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fitjmeq5uoor66e7yo1ua.png" alt="Image description" width="712" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;paymentOfOrder Function:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the paymentOfOrder function is called, a callback function is passed into it.&lt;/li&gt;
&lt;li&gt;Example: paymentOfOrder(() =&amp;gt; {}).&lt;/li&gt;
&lt;li&gt;Inside paymentOfOrder, this callback function is executed after completing the payment operation.&lt;/li&gt;
&lt;li&gt;By using this callback function, you can call orderSummary inside the callback after paymentOfOrder is done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbt1lrxt8gwa8759r5d04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbt1lrxt8gwa8759r5d04.png" alt="Image description" width="680" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;orderSummary Function:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the orderSummary function is called, a callback function is passed into it.&lt;/li&gt;
&lt;li&gt;Example: orderSummary(() =&amp;gt; {}).&lt;/li&gt;
&lt;li&gt;Inside orderSummary, this callback function is executed after completing the summary operation.&lt;/li&gt;
&lt;li&gt;By using this callback function, you can call updateWallet inside the callback after orderSummary is done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9c6aasw5lf69nq1kt0wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9c6aasw5lf69nq1kt0wd.png" alt="Image description" width="604" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Complete Flow with Explanations&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Here’s the complete flow with these explanations applied:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7znybgnq9nmmrspv50tm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7znybgnq9nmmrspv50tm.png" alt="Image description" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This expanded explanation should clarify how each function's callback is used to invoke the next function in the sequence, demonstrating the flow of execution and how callback functions are passed and executed at each step. &lt;/p&gt;

&lt;p&gt;This nesting of callbacks is what leads to callback hell as it makes the code harder to read and maintain, especially as the number of nested operations grows.&lt;/p&gt;

&lt;p&gt;Avoid callback hell, consider refactoring the code using Promises or async/await for better readability and maintainability, as previously demonstrated.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Next Blog will be Promises , How we solve the call back issue by promises.&lt;br&gt;
Keep following . Thank You&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>State and Props In React</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Sun, 09 Jun 2024 09:15:07 +0000</pubDate>
      <link>https://dev.to/pervez/state-and-props-in-react-4eib</link>
      <guid>https://dev.to/pervez/state-and-props-in-react-4eib</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is The State In React ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 State is a way to Keep Track of Data that can Change in your Application. State is a Plain JavaScript Object that holds information that may change during the components life cycle. this data directly Affects the Components behavior and appearance . When The state changes , React Re-renders the component with updated information , Ensuring the UI reflects the current State&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;key Points :✍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Internal :&lt;/strong&gt; State is local to it's Components and isn't modified outside the Components&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic :&lt;/strong&gt; Sate Can be Modified Throughout the Component Lifecycle Allowing for interactive and responsive UI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-rendering :&lt;/strong&gt; whenever the state Changes , React Retender the Component and reflecting the updating information on the UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How State Works ? ✍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State is typically Initialized in the constructor of class components and using useState() hooks in Functional Components.&lt;/li&gt;
&lt;li&gt;You Can directly access the state value using this.state in class components and state variable in functional components.&lt;/li&gt;
&lt;li&gt;State Should never mutated Directly . instead of , use this.setState method for class components and state updater Function in Functional components.&lt;/li&gt;
&lt;li&gt;when Updating State , Never modify the existing state , instead of , create a new object with desire changes and make a shallow a comparison for Re-renders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;👉 Props in React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Props are short for "properties" and are used to pass data from one component to another. They are read-only, meaning they cannot be modified by the receiving component. Props are typically used to pass data from a parent component to a child component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;key Points :✍&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutability:&lt;/strong&gt; Props are immutable. Once set by the parent component, the child component cannot change them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Flow:&lt;/strong&gt; Props enable a unidirectional data flow, meaning data flows from parent to child components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function Arguments:&lt;/strong&gt; Props work similarly to function arguments. When you define a component, you can pass data to it through attributes, just like passing arguments to a function.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>useState() Hooks In react , How it Works ?</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Sun, 09 Jun 2024 07:05:43 +0000</pubDate>
      <link>https://dev.to/pervez/usestate-hooks-in-react-how-it-works--1oh4</link>
      <guid>https://dev.to/pervez/usestate-hooks-in-react-how-it-works--1oh4</guid>
      <description>&lt;p&gt;👉 &lt;strong&gt;useState() Hooks In React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;useState() hooks is a function that allows you to add a state in functional components. When you call useState() hooks, it returns an array with two elements.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;State Variable:&lt;/strong&gt; The current value of the state.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;State Updater Function:&lt;/strong&gt; This function allows you to update the state variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 Example :&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tv0gu74pdvno7y15bz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5tv0gu74pdvno7y15bz6.png" alt="Image description" width="800" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;state:&lt;/strong&gt; The current state value.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;setState :&lt;/strong&gt; A function to update the state.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;initialState :&lt;/strong&gt; The initial value of the state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points 👍 :&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Initialization:&lt;/strong&gt; When the component first renders, useState(initialState) sets up a state variable (state) and a function (setState) to update that state. The initialState can be any type of value: number, string, object, array, etc.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;State Variable:&lt;/strong&gt; The state variable holds the current state value. React keeps track of this variable internally and ensures it stays consistent across re-renders.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;State Setter Function:&lt;/strong&gt; The setState function allows you to update the state. When you call this function with a new value, React schedules a re-render of the component, during which the state variable is updated with the new value.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Re-rendering:&lt;/strong&gt; When the state is updated, React re-renders the component to reflect the new state. This means the component function is called again, but the state variable will now hold the updated value.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Multiple State Variables:&lt;/strong&gt; You can use multiple useState hooks within a single component to manage different state variables independently, providing greater flexibility and readability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtn1p64d53fjq0ifld1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtn1p64d53fjq0ifld1p.png" alt="Image description" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Functional Updates:&lt;/strong&gt; Sometimes you need to update the state based on the previous state. In such cases, you can pass a function to the setState function. This function receives the previous state and returns the new state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczb3yqymdxjfcxesxyh9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczb3yqymdxjfcxesxyh9.png" alt="Image description" width="800" height="589"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using the functional form of setState, you ensure that the state update is based on the previous state, which is particularly important when updates depend on the previous state value&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Lazy Initialization:&lt;/strong&gt; If the initial state is the result of an expensive computation, you can pass a function to useState. This function will be called only once to compute the initial state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7l5bqailp2uj381tll6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7l5bqailp2uj381tll6.png" alt="Image description" width="800" height="755"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using this approach, you ensure that the expensive computation to determine the initial state is performed only once, rather than on every re-render of the component.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Handling Objects and Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When dealing with objects or arrays, you should remember that useState does not automatically merge updates. Instead, you need to manage merging state updates manually.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Updating an Object&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkukag22qy8jhxr1dpki0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkukag22qy8jhxr1dpki0.png" alt="Image description" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Add an Array&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnfaffoz5w4jpq1iyoagt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnfaffoz5w4jpq1iyoagt.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;useState is a versatile and powerful hook for managing state in functional components, providing an easy-to-use API that aligns with React's declarative nature. It simplifies state management, enhances readability, and contributes to more maintainable and scalable React applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Temporal Dead Zone In JavaScript</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Wed, 29 May 2024 18:47:52 +0000</pubDate>
      <link>https://dev.to/pervez/temporal-dead-zone-in-javascript-4ef8</link>
      <guid>https://dev.to/pervez/temporal-dead-zone-in-javascript-4ef8</guid>
      <description>&lt;p&gt;During the memory creation phase of the execution context, variables declared with let and const are allocated memory in the block scope, not in the global scope. These variables cannot be accessed before they are initialized. Here Temporal Dead Zone (TDZ) Comes To In Picture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 Temporal Dead Zone In JavaScript :&lt;/strong&gt;&lt;br&gt;
Temporal Dead Zone is a behavior in JavaScript where variables declared with let and const are inaccessible before their initialization.&lt;br&gt;
Temporal Dead Zone (TDZ) is the time period in JavaScript when a variable declared with let or const has memory allocated but has not yet been initialized.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttx07ibpphy519li72ut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fttx07ibpphy519li72ut.png" alt="Image description" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👇 Explanation Of Above Example :&lt;/strong&gt;&lt;br&gt;
During the memory creation phase, memory space is allocated for the variable 'a'. However, 'a' is not initialized yet. This marks the beginning of the Temporal Dead Zone (TDZ) for variable 'a'. The Temporal Dead Zone (TDZ) ends when variable 'a' is initialized with the value 1.&lt;/p&gt;

&lt;p&gt;Attempting to access 'a' variable in its TDZ will Throw  a &lt;em&gt;&lt;strong&gt;ReferenceError&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, the TDZ applies to &lt;strong&gt;_const _&lt;/strong&gt;variables as well&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyeimh9vb1gubj35ff15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyeimh9vb1gubj35ff15.png" alt="Image description" width="742" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👇 Explanation Of Above Example :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, a is properly declared and initialized before we attempt to access it, so there is no TDZ violation, and the value of a (which is 1) is successfully printed to the console.&lt;/p&gt;

&lt;p&gt;In summary, the TDZ is a period during which let and const variables exist but are not yet accessible. The TDZ ensures that variables are accessed only after they have been properly declared and initialized, &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>development</category>
    </item>
    <item>
      <title>How Function And Variables Works in JavaScript : Behind the Scenes</title>
      <dc:creator>Md Pervez Hossain</dc:creator>
      <pubDate>Wed, 29 May 2024 18:31:28 +0000</pubDate>
      <link>https://dev.to/pervez/how-function-and-variables-works-in-javascript-behind-the-scenes-gc5</link>
      <guid>https://dev.to/pervez/how-function-and-variables-works-in-javascript-behind-the-scenes-gc5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Function is The Heart Of JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything in JavaScript Happens Inside an Execution Context&lt;br&gt;
All JavaScript code runs within an execution context, which provides an environment for the code execution. When JavaScript code runs, it first creates a Global Execution Context (GEC). The GEC ( Global Execution Context )  Put Into The Call Stack .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Call Stack In JavaScript ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The call stack in JavaScript is a mechanism that helps the JavaScript engine keep track of function calls and their execution order. It follows the Last In, First Out (LIFO) principle, meaning that the last function called is the first one to complete execution and be removed from the stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It Has two main components:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memory Component&lt;/strong&gt; (Variable Environment)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Component&lt;/strong&gt; (Thread of Execution)&lt;/li&gt;
&lt;/ul&gt;

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