<?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 Englishjha on Medium]]></title>
        <description><![CDATA[Stories by Englishjha on Medium]]></description>
        <link>https://medium.com/@englishjha?source=rss-6404dec94b8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*b8fP9ECP9EFAXWqu</url>
            <title>Stories by Englishjha on Medium</title>
            <link>https://medium.com/@englishjha?source=rss-6404dec94b8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:03:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@englishjha/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[Question 1 — Basic]]></title>
            <link>https://medium.com/@englishjha/question-1-basic-cc6a6f018fcc?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc6a6f018fcc</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Mon, 17 Aug 2026 06:48:06 GMT</pubDate>
            <atom:updated>2026-08-17T17:32:17.498Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is Debouncing in JavaScript, and why would you use it in a real frontend project?</strong></p><p>“Debouncing is a technique used to reduce unnecessary function calls. For example, in a search input, instead of making an API request on every keystroke, we wait until the user stops typing for a certain amount of time, and then make the API call.”</p><p>“Debouncing le unnecessary function or API calls reduce garcha. For example, search ma user le each character type garda API call nagari, user le typing stop garepachi certain delay wait garera matra API call garchau.”</p><p><strong>Q Can you explain what happens if a user keeps typing continuously in a debounced search input?</strong></p><p><strong>Ideal Simple English:</strong></p><blockquote><em>“Debounce waits until the user stops triggering an event before executing the function. It is useful for search and auto-save. Throttle executes the function at a fixed interval while the event is continuously happening. It is useful for scroll, resize, or mousemove events.”</em></blockquote><p><strong>Nepali + English</strong></p><blockquote><em>“Debounce ma user ko activity stop bhayepachi matra function execute huncha, jasto search ra auto-save. Throttle ma activity continuously bhaye pani fixed interval ma function execute huncha, jasto scroll, resize, or mousemove.”</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc6a6f018fcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DAY 1 — Q6 EVALUATION]]></title>
            <link>https://medium.com/@englishjha/day-1-q6-evaluation-24f89c0b896b?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/24f89c0b896b</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Thu, 13 Aug 2026 10:40:16 GMT</pubDate>
            <atom:updated>2026-08-13T11:38:40.212Z</atom:updated>
            <content:encoded><![CDATA[<p>DAY 1 — Q6 EVALUATION</p><p>Q6.1<br>console.log(10 == “10”);</p><p>Your answer: true ✅</p><p>Why:<br>`==` le loose equality use garcha. JavaScript le comparison agadi<br>type coercion garna sakcha, so “10” lai number 10 ma convert garcha.</p><p>10 == “10”<br>→ 10 == 10<br>→ true</p><p>Q6.2<br>console.log(10 === “10”);</p><p>Your answer: false ✅</p><p>Why:<br>`===` le strict equality use garcha.<br>Value ra data type duitai same hunuparcha.</p><p>10 → number<br>“10” → string</p><p>Type फरक cha, so:<br>→ false</p><p>Q6.3<br>console.log(10 != “10”);</p><p>Your answer: false ✅</p><p>Why:<br>`!=` le loose inequality check garcha.<br>Comparison agadi coercion huna sakcha.</p><p>10 == “10”<br>→ true</p><p>Tesaile:</p><p>10 != “10”<br>→ false</p><p>Q6.4<br>console.log(10 !== “10”);</p><p>Correct output:<br>true ✅</p><p>Why:<br>`!==` le strict inequality check garcha.<br>Value same jasto dekhiye pani type different cha.</p><p>10 → number<br>“10” → string</p><p>So strict equality false huncha:</p><p>10 === “10”<br>→ false</p><p>Ani strict NOT equal:</p><p>10 !== “10”<br>→ true</p><p>FINAL ANSWER:</p><p>10 == “10” → true<br>10 === “10” → false<br>10 != “10” → false<br>10 !== “10” → true</p><p>INTERVIEW STYLE:</p><p>`==` ra `!=` ma JavaScript le type coercion garna sakcha,<br>so value equivalent cha ki chaina check garcha.</p><p>`===` ra `!==` strict comparison ho, jasma value ra data type<br>dubai consider huncha.</p><p>Example:<br>10 == “10” → true<br>10 === “10” → false</p><p>DAY 1 — INTERVIEW + CRUSH QUESTIONS</p><p>LEVEL 2 — CODE / OUTPUT</p><p>Q7:</p><p>console.log(typeof null);<br>console.log(typeof undefined);<br>console.log(typeof []);<br>console.log(typeof {});<br>console.log(typeof NaN);</p><p>YOUR ANSWER:</p><p>typeof null → object<br>But why it is object, I am not sure.</p><p>typeof undefined → object<br>All are object.</p><p>EVALUATION:</p><p>⚠️ Partially Correct</p><p>CORRECT OUTPUT:</p><p>typeof null → “object” ✅<br>typeof undefined → “undefined” ❌<br>typeof [] → “object”<br>typeof {} → “object”<br>typeof NaN → “number” ❗</p><p>1. typeof null</p><p>Output:</p><p>“object”</p><p>Yo JavaScript ko एउटा historical bug / legacy behavior ho.</p><p>`null` actually object hoina.<br>`null` le intentional absence of value represent garcha.</p><p>Tara JavaScript ko very early implementation dekhi `typeof null`<br>le `”object”` return gardai aayeko cha.</p><p>So:</p><p>typeof null<br>→ “object”</p><p>Important:<br>`typeof null === “object”` bhayeko matra le null lai real object<br>manne hoina.</p><p>Interview ma yesto bhanna sakincha:</p><p>“typeof null returning ‘object’ is a historical legacy behavior in JavaScript, even though null itself is not an object.”</p><p>2. typeof undefined</p><p>Output:</p><p>“undefined” ✅</p><p>`undefined` ko meaning generally value assign nagareko or value<br>available nabhayeko ho.</p><p>Example:</p><p>let name;</p><p>console.log(name);<br>// undefined</p><p>So:</p><p>typeof undefined<br>→ “undefined”</p><p>3. typeof []</p><p>Output:</p><p>“object”</p><p>Array JavaScript ma separate primitive type hoina.<br>Array object ko special type ho.</p><p>So:</p><p>typeof []<br>→ “object”</p><p>Array check garna:</p><p>Array.isArray([])<br>// true</p><p>4. typeof {}</p><p>Output:</p><p>“object”</p><p>Object obviously object type ho.</p><p>So:</p><p>typeof {}<br>→ “object”</p><p>5. typeof NaN</p><p>Output:</p><p>“number” ❗</p><p>Yo important interview trap ho.</p><p>`NaN` ko full meaning:<br>Not-a-Number</p><p>Name herda number jasto lagdaina, tara JavaScript ko<br>number type bhitra `NaN` represent huncha.</p><p>So:</p><p>typeof NaN<br>→ “number”</p><p>FINAL OUTPUT:</p><p>typeof null<br>→ “object”</p><p>typeof undefined<br>→ “undefined”</p><p>typeof []<br>→ “object”</p><p>typeof {}<br>→ “object”</p><p>typeof NaN<br>→ “number”</p><p>IMPORTANT INTERVIEW TRAPS:</p><p>1. `typeof null === “object”`<br> → historical legacy behavior</p><p>2. `typeof [] === “object”`<br> → arrays are objects in JavaScript</p><p>3. `typeof NaN === “number”`<br> → NaN belongs to the Number type</p><p>4. `undefined` is different from `null`<br> → undefined = value not assigned / unavailable<br> → null = intentional absence of value</p><p>INTERVIEW ANSWER — NEPALI + ENGLISH:</p><p>“`typeof null` ko result ‘object’ aaucha, but null actually object hoina. Yo JavaScript ko historical legacy behavior ho. `typeof undefined` le ‘undefined’ return garcha. Array ra normal object ko lagi ‘object’ aaucha, ra interestingly `typeof NaN` chai ‘number’ aaucha because NaN JavaScript ko Number type ko part ho.”</p><p>7-DAY REVISION NOTE:</p><p>`null` → typeof → “object” ⚠️ legacy behavior<br>`undefined` → typeof → “undefined”<br>`[]` → typeof → “object”<br>`{}` → typeof → “object”<br>`NaN` → typeof → “number” ⚠️ interview trap</p><p>DAY 1 — INTERVIEW + CRUSH QUESTIONS</p><p>LEVEL 2 — CODE / OUTPUT</p><p>Q8:</p><p>console.log(0 || “Hello”);<br>console.log(0 ?? “Hello”);</p><p>console.log(“” || “World”);<br>console.log(“” ?? “World”);</p><p>YOUR ANSWER:</p><p>1. 0 || “Hello” → False<br>2. 0 ?? “Hello” → “Hello”<br>3. “” || “World” → true<br>4. “” ?? “World” → true</p><p>EVALUATION:</p><p>❌ Partially Correct</p><p>Yaha main confusion `||` ra `??` ko actual behavior ma cha.</p><p>1. console.log(0 || “Hello”);</p><p>CORRECT OUTPUT:</p><p>“Hello” ✅</p><p>किन?</p><p>`||` le boolean true/false matra return garne hoina.<br>It returns the first truthy value.</p><p>`0` JavaScript ma falsy value ho.</p><p>So:</p><p>0 || “Hello”<br>→ 0 is falsy<br>→ next value “Hello”<br>→ “Hello”</p><p>2. console.log(0 ?? “Hello”);</p><p>CORRECT OUTPUT:</p><p>0 ❌</p><p>किन?</p><p>`??` le truthy/falsy check gardaina.</p><p>`??` le only yo check garcha:</p><p>LEFT SIDE `null` or `undefined` cha?</p><p>Yaha:</p><p>0</p><p>`0` null hoina<br>`0` undefined hoina</p><p>Tesaile:</p><p>0 ?? “Hello”<br>→ 0</p><p>Important:</p><p>`??` ma 0 valid value ho.</p><p>3. console.log(“” || “World”);</p><p>CORRECT OUTPUT:</p><p>“World” ❌</p><p>Yaha `””` empty string ho.<br>Empty string JavaScript ma falsy ho.</p><p>So:</p><p>“” || “World”<br>→ “” is falsy<br>→ “World”</p><p>Again, `||` returns a value, not `true`.</p><p>4. console.log(“” ?? “World”);</p><p>CORRECT OUTPUT:</p><p>“” ❌</p><p>किन?</p><p>`””` empty string ho, but empty string `null` or `undefined` hoina.</p><p>So `??` fallback ma jadaina.</p><p>Result:</p><p>“” ?? “World”<br>→ “”</p><p>FINAL OUTPUT:</p><p>0 || “Hello”<br>→ “Hello”</p><p>0 ?? “Hello”<br>→ 0</p><p>“” || “World”<br>→ “World”</p><p>“” ?? “World”<br>→ “”</p><p>IMPORTANT DIFFERENCE:</p><p>`||`</p><p>→ first truthy value return garcha<br>→ 0, “”, false, null, undefined, NaN lai falsy mancha</p><p>`??`</p><p>→ first value return garcha unless it is null or undefined<br>→ 0, “”, false are valid values</p><p>EASY MEMORY TRICK:</p><p>`||` → “Falsy cha bhane fallback deu”</p><p>`??` → “Null/Undefined cha bhane fallback deu”</p><p>REAL PROJECT EXAMPLE:</p><p>Suppose:</p><p>const count = 0;</p><p>count || 10<br>→ 10 ❌<br>because 0 is falsy</p><p>count ?? 10<br>→ 0 ✅<br>because 0 is valid and not null/undefined</p><p>INTERVIEW ANSWER — 70% NEPALI + 30% ENGLISH:</p><p>“`||` le first truthy value return garcha, so 0 ra empty string jasto falsy value bhaye second value ma jancha. `??` chai truthy/falsy check gardaina; it only checks null or undefined. Tesaile 0, false, ra empty string valid values hun, but null or undefined bhaye matra fallback value use huncha.”</p><p>7-DAY REVISION NOTE:</p><p>|| → first truthy value<br>?? → first non-nullish value</p><p>0 || “Hello” → “Hello”<br>0 ?? “Hello” → 0</p><p>“” || “World” → “World”<br>“” ?? “World” → “”</p><p>DAY 1 — INTERVIEW + CRUSH QUESTIONS</p><p>LEVEL 3–5-YEAR SENIOR TWIST</p><p>Q9:</p><p>const value = 0;</p><p>console.log(value || 100);<br>console.log(value ?? 100);</p><p>YOUR ANSWER:</p><p>1. value || 100 → 0<br>2. value ?? 100 → 100</p><p>EVALUATION:</p><p>❌ Both outputs are reversed.</p><p>But timro `||` ra `??` ko basic confusion identify bhayo, so aba clear banaum.</p><p>1. console.log(value || 100);</p><p>CORRECT OUTPUT:</p><p>100</p><p>KINa?</p><p>`||` le truthy value khojcha.</p><p>Yaha:</p><p>value = 0</p><p>`0` JavaScript ma falsy ho.</p><p>So:</p><p>0 || 100<br>→ 0 is falsy<br>→ second value 100 ma jancha<br>→ 100</p><p>Important:<br>`||` le “condition true bhayo bhane execute” matra gardaina.<br>It returns the first truthy operand.</p><p>2. console.log(value ?? 100);</p><p>CORRECT OUTPUT:</p><p>0</p><p>KINa?</p><p>`??` le truthy/falsy check gardaina.</p><p>It only checks:</p><p>null or undefined?</p><p>Yaha:</p><p>value = 0</p><p>0 ≠ null<br>0 ≠ undefined</p><p>So:</p><p>0 ?? 100<br>→ 0</p><p>Tesaile output 0 aaucha.</p><p>FINAL OUTPUT:</p><p>value || 100<br>→ 100</p><p>value ?? 100<br>→ 0</p><p>VERY IMPORTANT RULE:</p><p>`||`<br>→ first truthy value return garcha</p><p>`??`<br>→ first non-nullish value return garcha<br>→ null or undefined bhaye matra fallback value use garcha</p><p>REAL FRONTEND EXAMPLE:</p><p>const page = 0;</p><p>page || 1<br>→ 1</p><p>page ?? 1<br>→ 0</p><p>Suppose `0` is a valid value.<br>Teti bela `||` use garda valid 0 lai fallback le replace gardincha.</p><p>Tesaile appropriate situation ma `??` safer huncha.</p><p>INTERVIEW ANSWER — 70% NEPALI + 30% ENGLISH:</p><p>“`||` le first truthy value return garcha, so `0` falsy bhayeko le `100` return huncha. `??` chai null or undefined matra check garcha. `0` valid value ho, so `value ?? 100` le `0` nai return garcha. Tesaile valid zero or empty string jasto value preserve garnu parcha bhane, situation anusar `??` safer huncha.”</p><p>7-DAY REVISION NOTE:</p><p>0 || 100<br>→ 100</p><p>0 ?? 100<br>→ 0</p><p>Remember:</p><p>`||` → falsy fallback<br>`??` → null/undefined fallback</p><p>Q9 RESULT:</p><p>❌ Output wrong<br>⚠️ Concept still needs practice</p><p>But this is a good interview trap.<br>Yo concept clear bhayepachi Q8 ko confusion pani clear huncha.</p><p>NEXT — Q10 (5-Year Senior Twist)</p><p>const user = {<br> name: “”,<br> age: 0,<br> city: null<br>};</p><p>console.log(user.name || “Guest”);<br>console.log(user.name ?? “Guest”);</p><p>console.log(user.age || 18);<br>console.log(user.age ?? 18);</p><p>console.log(user.city || “Kathmandu”);<br>console.log(user.city ?? “Kathmandu”);</p><p>4 ota nahi, 6 ota output predict gara.<br>Each ko WHY pani explain gara.</p><p>DAY 1 — INTERVIEW + CRUSH QUESTIONS</p><p>LEVEL 3–5-YEAR SENIOR TWIST</p><p>Q10:</p><p>const user = {<br> name: “”,<br> age: 0,<br> city: null<br>};</p><p>console.log(user.name || “Guest”);<br>console.log(user.name ?? “Guest”);</p><p>console.log(user.age || 18);<br>console.log(user.age ?? 18);</p><p>console.log(user.city || “Kathmandu”);<br>console.log(user.city ?? “Kathmandu”);</p><p>YOUR ANSWER:</p><p>1. user.name || “Guest” → “”<br>2. user.name ?? “Guest” → “Guest”<br>3. user.age || 18 → 18<br>4. user.age ?? 18 → 0<br>5. user.city || “Kathmandu” → 0<br>6. user.city ?? “Kathmandu” → “Kathmandu”</p><p>EVALUATION:</p><p>⚠️ Partially Correct</p><p>Correct:<br>Q3 ✅<br>Q4 ✅<br>Q6 ✅</p><p>Wrong:<br>Q1 ❌<br>Q2 ❌<br>Q5 ❌</p><p>Q1. user.name || “Guest”</p><p>Correct output:</p><p>“Guest”</p><p>WHY?</p><p>user.name ko value `””` (empty string) ho.</p><p>Empty string JavaScript ma FALSE/FALSY ho.</p><p>`||` le first TRUTHY value return garcha.</p><p>So:</p><p>“” || “Guest”<br>→ “” is falsy<br>→ “Guest”</p><p>Therefore:</p><p>→ “Guest”</p><p>Q2. user.name ?? “Guest”</p><p>Correct output:</p><p>“”</p><p>WHY?</p><p>`??` le truthy/falsy check gardaina.</p><p>It only checks:</p><p>null OR undefined</p><p>Yaha:</p><p>user.name = “”</p><p>`””` null hoina.<br>`””` undefined pani hoina.</p><p>Tesaile fallback use hudaina.</p><p>So:</p><p>“” ?? “Guest”<br>→ “”</p><p>Therefore:</p><p>→ “”</p><p>Q3. user.age || 18</p><p>Correct output:</p><p>18 ✅</p><p>WHY?</p><p>user.age = 0</p><p>`0` falsy ho.</p><p>`||` le first truthy value khojcha.</p><p>So:</p><p>0 || 18<br>→ 18</p><p>Q4. user.age ?? 18</p><p>Correct output:</p><p>0 ✅</p><p>WHY?</p><p>`??` le only null/undefined check garcha.</p><p>0 valid value ho.</p><p>So:</p><p>0 ?? 18<br>→ 0</p><p>Q5. user.city || “Kathmandu”</p><p>Correct output:</p><p>“Kathmandu”</p><p>Timro answer `0` ❌</p><p>WHY?</p><p>user.city = null</p><p>`null` falsy ho.</p><p>`||` le first truthy value khojcha.</p><p>So:</p><p>null || “Kathmandu”<br>→ “Kathmandu”</p><p>VERY IMPORTANT:</p><p>`null` automatically 0 hudaina.</p><p>Yo timro main confusion ho.</p><p>Null ko numeric conversion kehi contexts ma 0 huna sakcha:</p><p>Number(null)<br>→ 0</p><p>Tara:</p><p>null || “Kathmandu”<br>→ “Kathmandu”</p><p>Because `||` le yaha numeric conversion garirako chaina.<br>It is checking truthiness.</p><p>Q6. user.city ?? “Kathmandu”</p><p>Correct output:</p><p>“Kathmandu” ✅</p><p>WHY?</p><p>user.city = null</p><p>`??` le null/undefined check garcha.</p><p>Yaha null cha.</p><p>So fallback:</p><p>→ “Kathmandu”</p><p>FINAL OUTPUT:</p><p>user.name || “Guest”<br>→ “Guest”</p><p>user.name ?? “Guest”<br>→ “”</p><p>user.age || 18<br>→ 18</p><p>user.age ?? 18<br>→ 0</p><p>user.city || “Kathmandu”<br>→ “Kathmandu”</p><p>user.city ?? “Kathmandu”<br>→ “Kathmandu”</p><p>MAIN CONCEPT:</p><p>`||`<br>→ first truthy value return garcha</p><p>Falsy values include:<br>0<br>“”<br>false<br>null<br>undefined<br>NaN</p><p>`??`<br>→ first non-nullish value return garcha</p><p>Only:<br>null<br>undefined</p><p>lai fallback garcha.</p><p>EASY MEMORY TRICK:</p><p>`||`<br>→ “Falsy bhaye fallback”</p><p>`??`<br>→ “Null/Undefined bhaye fallback”</p><p>REAL FRONTEND EXAMPLE:</p><p>const count = 0;</p><p>count || 10<br>→ 10 ❌</p><p>count ?? 10<br>→ 0 ✅</p><p>If 0 is a valid value, `??` often makes more sense.</p><p>INTERVIEW MA KE BHANNE?</p><p>“Yaha main difference `||` ra `??` ko fallback condition ho.<br>`||` le first truthy value return garcha, so empty string, 0,<br>false, null, undefined jasto falsy values bhaye fallback use huncha.<br>`??` chai only null or undefined ko case ma fallback use garcha.<br>Tesaile 0 or empty string valid value ho bhane `??` better choice huna sakcha.”</p><p>5-YEAR SENIOR INTERVIEW POINT:</p><p>Interviewer le sodhyo:</p><p>“Why would you choose ?? over ||?”</p><p>Timro answer:</p><p>“Because `||` le all falsy values lai fallback garna sakcha.<br>But many situations ma 0, false, or empty string valid values hun.<br>`??` le only null and undefined ko case ma fallback use garcha,<br>so it preserves valid falsy values.”</p><p>IMPORTANT CORRECTION FROM YOUR ANSWER:</p><p>❌ “null ko value JS ma 0 huncha”</p><p>Correct:</p><p>“null numeric conversion ko context ma 0 ma convert huna sakcha,<br>but null itself is not 0.”</p><p>Example:</p><p>Number(null)<br>→ 0</p><p>But:</p><p>null || “Kathmandu”<br>→ “Kathmandu”</p><p>7-DAY REVISION NOTE:</p><p>||:<br>0 → fallback<br>“” → fallback<br>false → fallback<br>null → fallback<br>undefined → fallback</p><p>??:<br>0 → keep 0<br>“” → keep “”<br>false → keep false<br>null → fallback<br>undefined → fallback</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24f89c0b896b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Async & Await (Production Guide)]]></title>
            <link>https://medium.com/@englishjha/javascript-async-await-production-guide-4353865ee8f8?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4353865ee8f8</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Fri, 24 Jul 2026 17:00:04 GMT</pubDate>
            <atom:updated>2026-11-24T05:12:40.993Z</atom:updated>
            <content:encoded><![CDATA[<h3>Senior React.js &amp; JavaScript Developer Interview (5+ Years Experience)</h3><h3>JavaScript Async &amp; Await</h3><p>Async/Await is one of the most important ES2017 (ES8) features that makes asynchronous JavaScript code easier to read, write, and maintain.</p><p>.then() र .catch() प्रयोग गरेर लामो Promise chain लेख्नुभन्दा <strong>Async/Await</strong> प्रयोग गर्दा asynchronous code लेख्न सजिलो हुन्छ।</p><p>In modern React applications, Async/Await is heavily used for:</p><ul><li>API Calls</li><li>Authentication</li><li>File Upload</li><li>Payment Integration</li><li>Database Requests</li><li>Background Jobs</li><li>Multiple API Calls</li><li>React Query / Redux Toolkit</li><li>Node.js Backend</li></ul><p>If you’re interviewing for a <strong>Senior React.js Developer (5+ Years Experience)</strong> position, Async/Await is one of the most frequently asked JavaScript topics.</p><h3>1. What is an Async Function?</h3><p>The async keyword एउटा function लाई asynchronous function बनाउँछ।</p><p><strong>Simple Explanation:</strong></p><p>Jaba hami function ko agadi async keyword lekchhau, JavaScript le automatically tyo function bata <strong>Promise return</strong> garcha.</p><p>Even if we return a normal value like a string, number, or boolean, async function always returns a Promise.</p><h3>2. Normal Function vs Async Function</h3><h3>A. Normal Function</h3><pre>function getName() {<br>    return &quot;Sachin&quot;;<br>}<br><br>const result = getName();<br><br>console.log(result);</pre><p><strong>Output:</strong></p><pre>&quot;Sachin&quot;</pre><p><strong>Explanation:</strong></p><ul><li>getName() function call huncha.</li><li>Function le &quot;Sachin&quot; return garcha.</li><li>result ma direct &quot;Sachin&quot; store huncha.</li></ul><p>Normal function le direct value return garcha.</p><h3>B. Async Function</h3><pre>async function getName() {<br>    return &quot;Sachin&quot;;<br>}<br><br>const result = getName();<br><br>console.log(result);</pre><p><strong>Output:</strong></p><pre>Promise {&lt;fulfilled&gt;: &quot;Sachin&quot;}</pre><p><strong>Explanation:</strong></p><ul><li>async keyword le function lai asynchronous function banaucha.</li><li>JavaScript le automatically Promise create garcha.</li><li>&quot;Sachin&quot; value Promise bhitra store huncha.</li><li>result ma Promise store huncha, direct string store hudaina.</li></ul><h3>3. How Does Async Automatically Return a Promise?</h3><pre>async function getAge() {<br>    return 25;<br>}</pre><p>JavaScript le yeslai conceptually yesto Promise result ko equivalent banaucha:</p><pre>function getAge() {<br>    return Promise.resolve(25);<br>}</pre><p><strong>Important:</strong> Yo conceptual comparison ho. JavaScript le exactly Promise.resolve() call nai garcha bhanne hoina.</p><h3>How it works:</h3><ol><li>We write async before the function.</li><li>JavaScript automatically makes the function return a Promise.</li><li>The returned value goes inside that Promise.</li><li>Promise fulfils with that value.</li></ol><p><strong>Remember:</strong></p><p>async = Automatically returns a Promise.</p><h3>4. Manual Promise vs Async Function</h3><h4>A. Manually Creating a Promise</h4><pre>const getAge = new Promise((resolve, reject)=&gt;{<br>  resolve (&quot;25&quot;);<br>})<br><br>getAge<br>.then((result)=&gt;console.log(result))Here:<br><br>outPut = 25;</pre><ul><li>new Promise() manually Promise create garcha.</li><li>resolve(25) le Promise successfully complete garcha.</li><li>Promise bhitra 25 value huncha.</li></ul><h4>B. Using Async Function</h4><pre>async function getAge() {<br>    return 25;<br>}</pre><p>Here:</p><ul><li>async le automatically Promise return garcha.</li><li>return 25 le Promise lai 25 value sanga fulfil garcha.</li></ul><p>Both functions return a Promise containing 25.</p><h3>5. How to Get the Actual Value from a Promise?</h3><p>Async function le Promise return garcha. Actual value pauna hami .then() or await use garna sakchhau.</p><h4>A. Using .then()</h4><pre>async function getName() {<br>    return &quot;Sachin&quot;;<br>}<br><br>getName().then((result) =&gt; {<br>    console.log(result);<br>});</pre><p><strong>Output:</strong></p><pre>Sachin</pre><p>.then() le Promise successfully fulfill bhayepachi actual value provide garcha.</p><h4>B. Using await</h4><pre>async function getName() {<br>    return &quot;Sachin&quot;;<br>}<br><br>async function showName() {<br>    const result = await getName();<br><br>    console.log(result);<br>}<br><br>showName();<br><br>Output:<br><br>Sachin</pre><p>await le Promise settle hune wait garcha ani fulfilled bhaye actual value dincha.</p><h4>6. Main Difference</h4><pre>## 6. Main Difference<br><br>| Normal Function | Async Function |<br>|---|---|<br>| Returns a direct value | Always returns a Promise |<br>| `return 25` | `return 25` |<br>| Output: `25` | Output: Promise containing `25` |<br>| Does not automatically create a Promise | Automatically returns a Promise |</pre><h4>7. Important Points to Remember</h4><ul><li>async is a JavaScript keyword.</li><li>It makes a function return a Promise.</li><li>We do not need to manually write new Promise().</li><li>A normal value returned from an async function becomes the fulfilled value of its Promise.</li><li>We can get the actual value using .then() or await.</li></ul><p><strong>One-line Interview Answer:</strong></p><p>An async function is a function declared with the async keyword. It always returns a Promise, and any normal value returned from it becomes the fulfilled value of that Promise.</p><h3>What is Await?</h3><p><strong>await</strong> keyword ले Promise resolve नभएसम्म function execution pause गर्छ।</p><p>Only async function भित्र await प्रयोग गर्न सकिन्छ.</p><pre>function fetchData() {<br>    return new Promise(resolve =&gt; {<br>        setTimeout(() =&gt; {<br>            resolve(&quot;Data Loaded&quot;);<br>        },2000);<br>    });<br>}</pre><pre>async function getData(){</pre><pre>    console.log(&quot;Loading...&quot;);</pre><pre>    const result = await fetchData();</pre><pre>    console.log(result);</pre><pre>}</pre><pre>getData();</pre><p>Output</p><pre>Loading...</pre><pre>(wait 2 seconds)</pre><pre>Data Loaded</pre><h3>How Async/Await Works Internally</h3><p>Interview मा धेरै सोधिने question.</p><p>Developer हरूले धेरैजसो answer दिन्छन्</p><blockquote><em>“await waits”</em></blockquote><p>तर त्यो complete answer होइन।</p><p>await ले JavaScript लाई pause गर्दैन। यसले केवल <strong>current async function</strong> लाई pause गर्छ। JavaScript Event Loop भने continuously run भइरहन्छ। Promise resolve भएपछि r<strong>emaining code Microtask Queue </strong>मा जान्छ र Call Stack empty भएपछि फेरि execute हुन्छ।</p><h3>☕ Real World Example — Coffee Shop</h3><p>Imagine तपाईं coffee shop मा जानुभयो।</p><h3>Characters</h3><ul><li>👨 <strong>You (Customer)</strong> = async function</li><li>👩‍🍳 <strong>Barista</strong> = Promise (who promises to prepare your coffee)</li><li>☕ <strong>Coffee Machine</strong> = Async Task (API, DB, Timer)</li><li>👥 <strong>Other Customers</strong> = Event Loop</li></ul><pre>function makeCoffee() {<br>  return new Promise((resolve) =&gt; {<br>    setTimeout(() =&gt; {<br>      console.log(&quot;☕ Coffee Ready&quot;);<br>      resolve(&quot;Coffee&quot;);<br>    }, 3000);<br>  });<br>}<br><br>async function customer() {<br>  console.log(&quot;Customer: Order Coffee&quot;);<br><br>  const coffee = await makeCoffee();<br><br>  console.log(&quot;Customer: Drink&quot;, coffee);<br>}<br><br>customer();<br><br>console.log(&quot;Cashier: Next Customer&quot;);</pre><p>Step 1</p><pre>customer();</pre><p>JavaScript customer() function भित्र जान्छ।</p><pre>Call Stack<br><br>customer()</pre><p>Step 2</p><pre>console.log(&quot;Customer: Order Coffee&quot;);<br><br>Output<br><br>Customer: Order Coffee<br><br>👉 Customer ले coffee order गर्यो।</pre><p>Step 3</p><p>अब यो line execute हुन्छ।</p><pre>await makeCoffee();<br><br>makeCoffee() start हुन्छ।<br><br>Coffee machine brewing सुरु गर्छ।<br><br>Coffee Machine<br><br>Making Coffee...<br><br>Promise अहिले<br><br>Pending</pre><p>Step 4 (Important)</p><p>JavaScript await मा पुग्यो।</p><p>धेरैलाई लाग्छ</p><pre>JavaScript waits here.</pre><p>❌ Wrong</p><p>Actually…</p><pre>Only customer() function pauses.</pre><p>JavaScript भने खाली बस्दैन।</p><p>customer() Call Stack बाट हट्छ।</p><pre>Call Stack<br><br>(empty)</pre><p>Step 5</p><p>अब JavaScript next line execute गर्छ।</p><pre>console.log(&quot;Cashier: Next Customer&quot;);<br><br>Output<br><br>Cashier: Next Customer</pre><h4>Real World</h4><p>Coffee तयार भएको छैन।</p><p>तर cashier ले अर्को customer लाई बोलाइरहेको छ।</p><p><strong>Exactly यही JavaScript ले पनि गर्छ।</strong></p><p>Event Loop ले अर्को काम continue गर्छ।</p><h4>Step 6</h4><p>३ seconds पछि…</p><p>Coffee तयार हुन्छ।</p><pre>☕ Coffee Ready<br><br>Promise<br><br>Pending<br><br>↓<br><br>Resolved</pre><h4>Step 7</h4><p>Promise resolve भएपछि</p><p>के JavaScript सीधा</p><pre>console.log(&quot;Customer: Drink Coffee&quot;);</pre><p>execute गर्छ?</p><p>❌ No.</p><p>पहिले यो code</p><pre>Customer: Drink Coffee</pre><p>Microtask Queue मा जान्छ।</p><pre>Microtask Queue<br><br>Resume customer()</pre><h4>Step 8</h4><p>Call Stack empty भएपछि</p><p>Event Loop ले Microtask Queue check गर्छ।</p><pre>Call Stack<br><br>↓<br><br>Empty<br><br>↓<br><br>Event Loop<br><br>↓<br><br>Microtask Queue<br><br>↓<br><br>Resume customer()</pre><p>अब execution continue हुन्छ।</p><pre>Customer: Drink Coffee</pre><p>Final Output</p><pre>Customer: Order Coffee<br>Cashier: Next Customer<br>☕ Coffee Ready<br>Customer: Drink Coffee</pre><h4>Internal Flow</h4><pre>customer()</pre><pre>↓</pre><pre>makeCoffee()</pre><pre>↓</pre><pre>Promise Pending</pre><pre>↓</pre><pre>await</pre><pre>↓</pre><pre>Pause only customer()</pre><pre>↓</pre><pre>Call Stack Empty</pre><pre>↓</pre><pre>JavaScript continues</pre><pre>↓</pre><pre>Promise Resolved</pre><pre>↓</pre><pre>Microtask Queue</pre><pre>↓</pre><pre>Event Loop</pre><pre>↓</pre><pre>Resume customer()</pre><pre>↓</pre><pre>After await executes</pre><h4>One Line Interview Answer ⭐</h4><p><strong>await does not block JavaScript. </strong><strong>await केवल current async function लाई pause गर्छ। JavaScript Event Loop भने continuously run भइरहन्छ। Promise resolve भएपछि </strong><strong>await पछिको code Microtask Queue मा जान्छ, र Call Stack empty भएपछि फेरि execution resume हुन्छ।</strong></p><h4>Easy Remember Trick 🧠</h4><p>Think like a <strong>restaurant</strong>:</p><ul><li>👤 Customer = async function</li><li>☕ Coffee Order = Async operation</li><li>👩‍🍳 Barista = Promise</li><li>💺 Customer waits on the side = await pauses only that function</li><li>👥 Restaurant keeps serving others = Event Loop keeps running</li><li>☕ Coffee ready = Promise resolved</li><li>🔔 Waiter calls customer = Microtask Queue</li><li>👤 Customer gets coffee = Async function resumes</li></ul><p><strong>Remember this sentence for interviews:</strong></p><blockquote><strong><em>“await does not stop JavaScript; it only pauses the current async function. The Event Loop keeps running, and once the Promise resolves, execution resumes through the Microtask Queue.&quot;</em></strong></blockquote><p>Important</p><p><strong>JavaScript thread कहिल्यै block हुँदैन।</strong></p><p>Only async function pause हुन्छ।</p><h3>Execution Flow</h3><pre>console.log(&quot;Start&quot;);</pre><pre>async function demo(){</pre><pre>    console.log(&quot;Inside&quot;);</pre><pre>    await Promise.resolve();</pre><pre>    console.log(&quot;After Await&quot;);</pre><pre>}</pre><pre>demo();</pre><pre>console.log(&quot;End&quot;);</pre><p>Output</p><pre>Start</pre><pre>Inside</pre><pre>End</pre><pre>After Await</pre><p>Interview Question</p><p>Why “End” prints before “After Await”?</p><p>Answer</p><p>Because await schedules remaining code into Microtask Queue.</p><h3>Async Function Always Returns Promise</h3><pre>async function demo(){ <br>   return 100;<br>}</pre><pre>console.log(demo());</pre><p>Output</p><pre>Promise {100}</pre><p>Equivalent</p><pre>function demo(){    <br>   return Promise.resolve(100);<br>}</pre><h3>Await with Promise</h3><pre>function getUser(){</pre><pre>    return Promise.resolve({</pre><pre>        name:&quot;Sachin&quot;</pre><pre>    });</pre><pre>}</pre><pre>async function fetchUser(){</pre><pre>    const user = await getUser();</pre><pre>    console.log(user);</pre><pre>}</pre><pre>fetchUser();</pre><p>Output</p><pre>{name:&quot;Sachin&quot;}</pre><h3>Error Handling</h3><p>Never ignore errors.</p><p>Always use</p><pre>try{</pre><pre>}<br>catch{</pre><pre>}</pre><p>Example</p><pre>async function getUsers(){</pre><pre>    try{</pre><pre>        const response = await fetch(&quot;/users&quot;);</pre><pre>        const data = await response.json();</pre><pre>        console.log(data);</pre><pre>    }</pre><pre>    catch(error){</pre><pre>        console.log(error);</pre><pre>    }</pre><pre>}</pre><p>Production Rule</p><p>Never leave await without proper error handling.</p><h3>Multiple Await Problem</h3><p>Bad</p><pre>const users = await getUsers();</pre><pre>const products = await getProducts();</pre><pre>const orders = await getOrders();</pre><p>Total Time</p><pre>2 sec</pre><pre>+</pre><pre>2 sec</pre><pre>+</pre><pre>2 sec</pre><pre>=</pre><pre>6 sec</pre><p>Production applications should avoid this unless every call depends on the previous result.</p><h3>Promise.all()</h3><p>Better</p><pre>const [users,products,orders]=await Promise.all([</pre><pre>    getUsers(),</pre><pre>    getProducts(),</pre><pre>    getOrders()</pre><pre>]);</pre><p>Execution</p><pre>All requests start together</pre><pre>↓</pre><pre>Fastest waits</pre><pre>↓</pre><pre>Slowest completes</pre><pre>↓</pre><pre>Total ≈ 2 sec</pre><p>Huge performance improvement.</p><h3>Promise.allSettled()</h3><p>If one API fails but others should continue.</p><pre>const results=await Promise.allSettled([</pre><pre>    getUsers(),</pre><pre>    getProducts(),</pre><pre>    getOrders()</pre><pre>]);</pre><p>Useful for</p><p>Dashboard</p><p>Analytics</p><p>Widgets</p><p>Notifications</p><p>Independent API calls</p><h3>Promise.race()</h3><p>Returns whichever finishes first.</p><p>Example</p><pre>const result=await Promise.race([</pre><pre>    fetchData(),</pre><pre>    timeout()</pre><pre>]);</pre><p>Useful for</p><p>API timeout implementation.</p><h3>Common Production Example</h3><p>Fetching User Profile</p><pre>async function loadProfile(){</pre><pre>    try{</pre><pre>        const response=await fetch(&quot;/api/profile&quot;);</pre><pre>        if(!response.ok){</pre><pre>            throw new Error(&quot;API Failed&quot;);</pre><pre>        }</pre><pre>        const data=await response.json();</pre><pre>        return data;</pre><pre>    }</pre><pre>    catch(error){</pre><pre>        console.log(error);</pre><pre>    }</pre><pre>}</pre><h3>React Example</h3><pre>useEffect(()=&gt;{</pre><pre>    async function load(){</pre><pre>        const users=await getUsers();</pre><pre>        setUsers(users);</pre><pre>    }</pre><pre>    load();</pre><pre>},[]);</pre><p>Wrong</p><pre>useEffect(async()=&gt;{</pre><pre>});</pre><p>Interview Question</p><p>Why?</p><p>Because useEffect callback should return a cleanup function, not a Promise.</p><h3>Async in Event Handler</h3><pre>const handleSubmit=async()=&gt;{</pre><pre>    try{</pre><pre>        setLoading(true);</pre><pre>        await saveUser();</pre><pre>    }</pre><pre>    finally{</pre><pre>        setLoading(false);</pre><pre>    }</pre><pre>}</pre><p>Production pattern.</p><h3>Async Inside Loop</h3><p>Bad</p><pre>for(const user of users){</pre><pre>    await save(user);</pre><pre>}</pre><p>Runs sequentially.</p><p>Better</p><pre>await Promise.all(</pre><pre>users.map(save)</pre><pre>);</pre><p>Much faster.</p><h3>Performance Best Practices</h3><p>✅ Use Promise.all() whenever tasks are independent.</p><p>✅ Avoid unnecessary await.</p><p>✅ Handle errors properly.</p><p>✅ Show loading indicator.</p><p>✅ Cancel unnecessary API requests.</p><p>✅ Cache repeated requests.</p><p>✅ Avoid nested async functions.</p><p>✅ Use AbortController.</p><h3>Common Mistakes</h3><h3>Forgetting await</h3><pre>const users=getUsers();</pre><pre>console.log(users);</pre><p>Returns Promise instead of data.</p><h3>Missing try/catch</h3><p>Unhandled Promise Rejection.</p><h3>Using await inside forEach</h3><p>Wrong</p><pre>users.forEach(async user=&gt;{</pre><pre>    await save(user);</pre><pre>});</pre><p>Correct</p><pre>await Promise.all(</pre><pre>users.map(save)</pre><pre>);</pre><h3>Overusing await</h3><p>Sequential code becomes slow.</p><h3>Async useEffect</h3><p>Wrong</p><pre>useEffect(async()=&gt;{</pre><pre>});</pre><p>Correct</p><pre>useEffect(()=&gt;{</pre><pre>    async function load(){</pre><pre>    }</pre><pre>    load();</pre><pre>},[]);</pre><h3>Real World Use Cases</h3><ul><li>Authentication Login</li><li>JWT Refresh Token</li><li>Payment Gateway</li><li>Stripe Integration</li><li>Razorpay</li><li>File Upload</li><li>Image Compression</li><li>AWS S3 Upload</li><li>Firebase</li><li>MongoDB Query</li><li>MySQL Query</li><li>Express API</li><li>Dashboard APIs</li><li>Notifications</li><li>Background Sync</li><li>Chat Applications</li><li>Infinite Scroll</li><li>Search Suggestions</li></ul><h3>Senior Interview Questions (5+ Years Experience)</h3><h3>Q1. Why does every async function return a Promise?</h3><p><strong>Answer:</strong> The async keyword automatically wraps the return value in Promise.resolve(), so callers can always use .then(), .catch(), or await.</p><h3>Q2. Can we use await without async?</h3><p><strong>Answer:</strong> Only inside ES Modules at the top level (Top-Level Await). In normal functions, await must be inside a async function.</p><h3>Q3. What happens internally when await is encountered?</h3><p><strong>Answer:</strong> The current async function pauses, the event loop continues processing other tasks, and when the Promise settles, the remaining code resumes from the microtask queue.</p><h3>Q4. Difference between Promise and Async/Await?</h3><p>PromiseAsync/AwaitUses .then() / .catch()Uses async / awaitMore suitable for chaining. More readable for sequential async logic. Can become nested. Cleaner and easier to maintain</p><h3>Q5. Promise.all() vs Promise.allSettled()</h3><p><strong>Answer:</strong> Promise.all() Fails immediately if any Promise rejects. Promise.allSettled() Waits for every Promise to finish and returns the status of each, making it useful for independent operations.</p><h3>Q6. Why shouldn’t we use async directly in useEffect()?</h3><p><strong>Answer:</strong> Because the useEffect callback must return either undefined or a cleanup function. A async function always returns a Promise, which React ignores.</p><h3>Q7. Why is await inside a loop usually slower?</h3><p><strong>Answer:</strong> Each iteration waits for the previous one to finish, making execution sequential. When operations are independent, Promise.all() allows them to run concurrently.</p><h3>Q8. What is the difference between concurrency and parallelism in JavaScript?</h3><p><strong>Answer:</strong> JavaScript provides concurrency through the event loop and asynchronous APIs. Code appears to run simultaneously, but JavaScript itself executes on a single thread unless additional workers or threads are used.</p><h3>Final Interview Tip</h3><p>For a Senior React.js Developer interview, don’t stop at explaining async and await. Interviewers often expect you to discuss:</p><ul><li>Event Loop</li><li>Call Stack</li><li>Web APIs</li><li>Microtask Queue</li><li>Promise lifecycle</li><li>Error handling</li><li>Concurrency</li><li>Promise.all()</li><li>Promise.allSettled()</li><li>AbortController</li><li>React useEffect patterns</li><li>API performance optimization</li><li>Race conditions</li><li>Memory leaks</li><li>Production debugging</li></ul><p>Being able to connect these concepts to real-world React applications is what differentiates a senior developer from someone who only knows the syntax.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4353865ee8f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Blog Link]]></title>
            <link>https://medium.com/@englishjha/javascript-advance-8245eb4ed521?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8245eb4ed521</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 10:34:25 GMT</pubDate>
            <atom:updated>2026-11-23T08:38:32.253Z</atom:updated>
            <content:encoded><![CDATA[<h3>1 ) JavaScript callback</h3><h4><a href="https://chatgpt.com/share/6b03f91f-1fc4-83ec-b012-aaae94aa3ad1">Article</a></h4><h3>2) Promise</h3><h4><a href="https://chatgpt.com/share/6b03f91f-1fc4-83ec-b012-aaae94aa3ad1">Article</a></h4><h4><a href="https://chatgpt.com/s/t_6a40f89001608191b8920cba9bb07b70">Q &amp; A</a></h4><h3>3)JavaScript Async &amp; Await</h3><h4><a href="https://medium.com/@englishjha/javascript-async-await-production-guide-4353865ee8f8?postPublishedType=initial">Article</a></h4><h4><a href="https://chatgpt.com/s/t_6a40ffebfdc08191a051ba17c0de4c0d">Q &amp; A</a></h4><h3>4) JavaScript Error Handling</h3><h4><a href="https://chatgpt.com/s/t_6a410ea20df48191b9aa5639ff23617d"><em>Article</em></a></h4><h4>Q <a href="https://chatgpt.com/s/t_6a41112fd73c819180200085c81d803c">&amp;</a> A</h4><h3>5) JavaScript Debounce &amp; Throttle</h3><p><a href="https://chatgpt.com/s/t_6a9eddd7070c819182531aaba4ae8d67">Article</a></p><h3>6) Understanding JavaScript Event Propagation: Bubbling, Capturing &amp; Delegation (Interview Perspective</h3><p><a href="https://medium.com/@englishjha/understanding-javascript-event-propagation-bubbling-capturing-delegation-interview-perspective-bbf28a040a17">Article</a></p><h3>7 ) JavaScript Control Flow and Error Handling — Complete Interview Preparation Guide</h3><p><a href="https://medium.com/@englishjha/javascript-control-flow-and-error-handling-complete-interview-preparation-guide-a3cc1c643075">Article</a></p><h3>8) JavaScript Memory Management (Stack vs Heap) 🚀</h3><p><a href="https://medium.com/@englishjha/javascript-memory-management-stack-vs-heap-9680976c1828">Article</a></p><h3>9 ) Expression and Operators</h3><p><a href="https://medium.com/@englishjha/experssion-an-doperators-a1ca1214a3af">Article</a></p><h3>10 ) Event Loop in JavaScript Explained Simply 🚀</h3><p><a href="https://medium.com/@englishjha/how-javascript-work-5b8d74372fac">Article</a></p><h3><strong>11) Closure</strong></h3><p><a href="https://chatgpt.com/s/t_6a8b0095be4881918c941ee8cd20307e">Article</a></p><h3>12 This</h3><p><a href="https://chatgpt.com/s/t_6a8b087445688191899aa59ec3917072">Article</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8245eb4ed521" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blog Links Reactjs]]></title>
            <link>https://medium.com/@englishjha/state-e19dc3a10dfd?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e19dc3a10dfd</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Sat, 13 Jun 2026 07:27:44 GMT</pubDate>
            <atom:updated>2026-11-10T14:45:31.186Z</atom:updated>
            <content:encoded><![CDATA[<h3>Important 40 JavaScript questions and answers</h3><h4><a href="https://www.theboringeducation.com/interview-prep/javascript-interview-questions">link</a></h4><h3>1 ) State</h3><h4>Article</h4><p><a href="https://chatgpt.com/c/6a2c3d8c-8840-83ee-8b4b-1cc32ddf8af4"><strong>React useState Hook Explained: State Management &amp; Re-renders (Interview-Focused Guide)</strong></a></p><h4>Question and Answer</h4><p><a href="https://chatgpt.com/s/t_6a2d0cf8caa48191a848c8b8813ad4a5">Check out this chat</a></p><h3>2 ) Props</h3><p><strong>Article</strong></p><p><a href="https://chatgpt.com/s/t_6a30291f1ca08191af0c4bc66d44de01">Check out this chat</a></p><h3>3 ) Conditional Rendering</h3><p><strong>Article</strong></p><p><a href="https://chatgpt.com/s/t_6a302c6b0c1c8191995bdaedb1adc382">https://chatgpt.com/s/t_6a302c6b0c1c8191995bdaedb1adc382</a></p><h4><strong>Question and answer</strong></h4><p><a href="https://chatgpt.com/s/t_6a302f42f8488191961ac91bf83484f5">https://chatgpt.com/s/t_6a302f42f8488191961ac91bf83484f5</a></p><p><a href="https://chatgpt.com/s/t_6a302c6b0c1c8191995bdaedb1adc382">Check out this chat</a></p><h3>4 ) React Keys</h3><p>Article</p><p><a href="https://chatgpt.com/s/t_6a3038e347c08191bfa0e4a4c53b53ba">Check out this chat</a></p><h3><strong>5) Function Component</strong></h3><h4>Article</h4><p><strong>https://chatgpt.com/s/t_6a3173330fa08191b3b98b26894c6804</strong></p><p><strong>Question and Answer</strong></p><p><a href="https://chatgpt.com/s/t_6a31740dc49c81918411d313a0e20996">Check out this chat</a></p><h3>6 ) List in ReactJS</h3><p><a href="https://chatgpt.com/s/t_6a3175059724819195da2b59f8ef14aa">Check out this chat</a></p><h3><strong>7) useEffect in ReactJS</strong></h3><h4>A<a href="https://chatgpt.com/s/t_6a3fcced118081918e476744cb8494e1">rticle</a></h4><h3>8) useRef</h3><h4><a href="https://chatgpt.com/s/t_6a3fd599b1c48191b90a241390ab5306">Article</a></h4><p><a href="https://chatgpt.com/s/t_6a40a9d0fe8c8191a4e1961e9f9a489d">Interview Q &amp; A</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e19dc3a10dfd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Lifting State Up: Senior Developer Interview Guide with Real-World Examples]]></title>
            <link>https://medium.com/@englishjha/react-lifting-state-up-senior-developer-interview-guide-with-real-world-examples-f1d43c647bdc?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1d43c647bdc</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 17:22:29 GMT</pubDate>
            <atom:updated>2026-06-11T17:22:29.533Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>React interview मा frequently सोधिने एउटा concept हो <strong>Lifting State Up</strong>।</p><p>Junior level मा interviewer ले सामान्य definition सोध्न सक्छ भने Senior React Developer interview मा यस्ता प्रश्न आउन सक्छन्:</p><ul><li><strong>What is Lifting State Up?</strong></li><li><strong>Why do we need it?</strong></li><li><strong>When should we avoid it?</strong></li><li><strong>What are the alternatives?</strong></li><li><strong>How does it compare with Context API or Zustand?</strong></li><li><strong>Can lifting state up create performance issues?</strong></li></ul><p>यदि तपाईं React.js वा Next.js Developer हुनुहुन्छ भने यो concept राम्रोसँग बुझ्न आवश्यक छ किनकि production applications मा components बीच data sharing धेरै common requirement हो।</p><h3>What is Lifting State Up?</h3><p>Simple definition:</p><blockquote><em>When multiple components need access to the same state, move that state to their nearest common parent component and pass it down through props.</em></blockquote><p>नेपालीमा बुझ्दा,</p><p>यदि दुई वा धेरै components ले एउटै data use गर्नुपर्छ भने state लाई child component भित्र नराखेर common parent component मा राख्ने process लाई Lifting State Up भनिन्छ।</p><h3>Why Do We Need Lifting State Up?</h3><p>धेरै developers ले सुरुमा यस्तो architecture बनाउँछन्:</p><pre>InputComponent<br> └─ useState()</pre><pre>DisplayComponent<br> └─ useState()</pre><p>दुवै component सँग आफ्नै state हुन्छ।</p><p>Problem के हुन्छ?</p><ul><li>Duplicate state</li><li>Data inconsistency</li><li>Difficult debugging</li><li>Unpredictable UI</li></ul><p>Example:</p><p>Input मा “React” type गरियो।</p><p>Display component ले अझै “Hello” देखाइरहेको छ।</p><p>अब state synchronization समस्या सुरु हुन्छ।</p><h3>Single Source of Truth</h3><p>React को एउटा महत्वपूर्ण principle हो:</p><blockquote><em>There should be a single source of truth.</em></blockquote><p>Real-world project मा एउटै data को multiple copies राख्नु खराब practice मानिन्छ।</p><p>Instead:</p><pre>App<br> ├── InputComponent<br> └── DisplayComponent</pre><p>Parent component ले state manage गर्छ।</p><p>Children ले केवल props receive गर्छन्।</p><h3>Basic Example</h3><h3>Child Component</h3><pre>function SearchInput({<br>  searchTerm,<br>  onSearchChange<br>}) {<br>  return (<br>    &lt;input<br>      value={searchTerm}<br>      onChange={(e) =&gt;<br>        onSearchChange(e.target.value)<br>      }<br>    /&gt;<br>  );<br>}</pre><h3>Result Component</h3><pre>function SearchPreview({<br>  searchTerm<br>}) {<br>  return (<br>    &lt;p&gt;<br>      Searching for: {searchTerm}<br>    &lt;/p&gt;<br>  );<br>}</pre><h3>Parent Component</h3><pre>function App() {<br>  const [searchTerm, setSearchTerm] =<br>    useState(&quot;&quot;);<br><br>  return (<br>    &lt;&gt;<br>      &lt;SearchInput<br>        searchTerm={searchTerm}<br>        onSearchChange={setSearchTerm}<br>      /&gt;<br><br>      &lt;SearchPreview<br>        searchTerm={searchTerm}<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>अब searchTerm को एउटै source छ।</p><p>दुवै components synchronized छन्।</p><h3>Real-World Senior Level Example</h3><p>अब एउटा e-commerce application को example हेरौं।</p><p>Suppose:</p><p>Product Filter Sidebar</p><pre>Price Filter<br>Category Filter<br>Brand Filter</pre><p>Product Listing Section</p><pre>Nike Shoes<br>Adidas Shoes<br>Puma Shoes</pre><h3>Wrong Approach</h3><p>Sidebar component मा filter state राख्ने।</p><pre>Sidebar<br> └─ useState()</pre><p>ProductList component मा फेरि API call गर्ने।</p><pre>ProductList<br> └─ useState()</pre><p>Problem:</p><ul><li>Data duplication</li><li>Sync issue</li><li>Multiple API calls</li><li>Difficult maintenance</li></ul><h3>Better Architecture</h3><pre>ProductsPage<br> ├── FilterSidebar<br> └── ProductList</pre><p>State parent मा राख्ने।</p><pre>const [filters, setFilters] =<br>  useState({<br>    category: &quot;&quot;,<br>    brand: &quot;&quot;,<br>    price: &quot;&quot;<br>  });</pre><p>अब:</p><p>FilterSidebar</p><pre>setFilters()</pre><p>ProductList</p><pre>filters</pre><p>receive गर्छ।</p><p>Production-grade architecture यही हो।</p><h3>Modal Example (Interview Favorite)</h3><p>Suppose:</p><pre>UserTable<br> ├── UserRow<br> └── EditUserModal</pre><p>Requirement:</p><p>Edit button click गर्दा modal खुल्नुपर्छ।</p><p>Wrong:</p><pre>UserRow<br> └─ modal state</pre><pre>EditModal<br> └─ modal state</pre><p>Correct:</p><pre>UsersPage<br> ├─ selectedUser<br> ├─ isModalOpen<br> ├─ UserTable<br> └─ EditModal</pre><p>Parent component ले state manage गर्छ।</p><p>This is a classic Lifting State Up use case.</p><h3>Senior Interview Question</h3><h3>Why Not Use Lifting State Up Everywhere?</h3><p>यो धेरै important interview question हो।</p><p>Lifting State Up राम्रो solution भए पनि हरेक ठाउँमा प्रयोग गर्नु हुँदैन।</p><p>Suppose:</p><pre>App<br> ├─ Layout<br> ├─ Sidebar<br> ├─ Dashboard<br> ├─ Analytics<br> ├─ Reports<br> └─ Settings</pre><p>यदि सबै state App component मा राखियो भने:</p><pre>App.jsx</pre><p>1000+ lines हुन सक्छ।</p><p>यसलाई State Explosion भनिन्छ।</p><p>Problems:</p><ul><li>Prop Drilling</li><li>Re-render issues</li><li>Hard Maintenance</li><li>Complex architecture</li></ul><h3>When Should You Use Context API?</h3><p>यदि data धेरै deeply nested components सम्म पुग्नुपर्छ भने:</p><pre>App<br> └─ Layout<br>     └─ Sidebar<br>         └─ UserProfile<br>             └─ Avatar</pre><p>Props pass गर्दै जानु practical हुँदैन।</p><p>Use:</p><pre>React Context API</pre><p>instead of excessive lifting state up.</p><h3>When Should You Use Zustand or Redux?</h3><p>Enterprise applications मा:</p><ul><li>Authentication</li><li>Cart</li><li>Notifications</li><li>User Preferences</li><li>Theme</li></ul><p>जस्ता globally shared state को लागि</p><p>Use:</p><ul><li>Zustand</li><li>Redux Toolkit</li><li>Jotai</li></ul><p>instead of lifting state up.</p><h3>Performance Consideration</h3><p>Senior interviews मा सोधिने अर्को question:</p><h3>Does lifting state up affect performance?</h3><p>Answer:</p><p>Yes, it can.</p><p>जब parent state update हुन्छ:</p><pre>setState()</pre><p>Parent re-render हुन्छ।</p><p>Children पनि re-render हुन सक्छन्।</p><p>Example:</p><pre>Dashboard<br> ├── Chart<br> ├── Table<br> ├── Sidebar<br> └── Header</pre><p>Search input update गर्दा सम्पूर्ण dashboard re-render हुन सक्छ।</p><p>Optimization:</p><pre>React.memo()<br>useMemo()<br>useCallback()</pre><h3>Interview Questions &amp; Answers</h3><h3>Q1. What is Lifting State Up?</h3><p>Moving state to the nearest common parent so multiple components can share the same data.</p><h3>Q2. Why is it important?</h3><p>To maintain a single source of truth and keep components synchronized.</p><h3>Q3. What problems does it solve?</h3><ul><li>Duplicate state</li><li>Data inconsistency</li><li>Communication between siblings</li></ul><h3>Q4. What are its disadvantages?</h3><ul><li>Prop drilling</li><li>Parent component becomes large</li><li>Unnecessary re-renders</li></ul><h3>Q5. What are alternatives?</h3><ul><li>Context API</li><li>Redux Toolkit</li><li>Zustand</li></ul><h3>Senior Developer Takeaway</h3><p>Lifting State Up भनेको केवल React interview को topic मात्र होइन।</p><p>Production applications मा:</p><ul><li>Filter Systems</li><li>Search Features</li><li>Multi-Step Forms</li><li>Shopping Cart</li><li>User Management</li><li>Modal Management</li><li>Dashboard Applications</li></ul><p>जस्ता features build गर्दा दैनिक रूपमा प्रयोग हुने pattern हो।</p><p>A strong React developer knows:</p><ul><li>When to lift state up</li><li>When NOT to lift state up</li><li>When to use Context API</li><li>When to use Global State Management</li></ul><p>यही decision-making capability ले Mid-Level Developer र Senior Developer बीचको फरक देखाउँछ।</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1d43c647bdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding JavaScript Event Propagation: Bubbling, Capturing & Delegation (Interview Perspective]]></title>
            <link>https://medium.com/@englishjha/understanding-javascript-event-propagation-bubbling-capturing-delegation-interview-perspective-bbf28a040a17?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbf28a040a17</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 16:51:58 GMT</pubDate>
            <atom:updated>2026-11-27T11:04:13.115Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>JavaScript interview मा Event Propagation एउटा धेरै common question हो।</p><p>React, Next.js, Vanilla JavaScript, DOM Manipulation, Event Handling जस्ता topics मा काम गर्दा Event Bubbling, Event Capturing र Event Delegation को clear understanding हुन आवश्यक छ।</p><p>Senior Developer Interview मा प्रायः यस्ता प्रश्न सोधिन्छन्:</p><ul><li>What is Event Propagation?</li><li>Explain Event Bubbling and Capturing.</li><li>What is Event Delegation?</li><li>Why is Event Delegation better for performance?</li><li>How does React handle events internally?</li></ul><p>यस article मा हामी theory मात्र होइन, real-world React/Next.js use cases पनि बुझ्नेछौं।</p><h3>What is Event Propagation?</h3><p>जब browser मा कुनै event trigger हुन्छ (click, keydown, submit आदि), त्यो event केवल target element मा मात्र execute हुँदैन।</p><p>Event DOM Tree भित्र travel गर्छ।</p><p>This process is called <strong>Event Propagation</strong>.</p><p>DOM Event Lifecycle consists of three phases:</p><ol><li><strong>Capturing Phase</strong></li><li><strong>Target Phase</strong></li><li><strong>Bubbling Phase</strong></li></ol><pre>Document<br>  ↓<br>HTML<br>  ↓<br>BODY<br>  ↓<br>DIV<br>  ↓<br>BUTTON (Target)<br>  ↑<br>DIV<br>  ↑<br>BODY<br>  ↑<br>HTML<br>  ↑<br>Document</pre><h3>Interview Answer</h3><blockquote><strong>Event Propagation:</strong> The process of an event moving through the DOM, from parent to child or child to parent.</blockquote><h3>Event Bubbling</h3><p>Event Bubbling भनेको child element बाट parent element तिर event माथि जाने process हो।</p><p>Event bubbling is a process where an event starts from the target element and moves upward to its parent elements.</p><p>Maanau timro HTML ma 3 ota elements chan:</p><ul><li>Grandparent</li><li>Parent</li><li>Child (Button)</li></ul><p>Aba timile Child button ma click garyau bhane event sabai bhanda pahila Child ma trigger huncha. Tespachi Parent hudai Grandparent samma jancha.</p><p>Example:</p><pre>&lt;div id=&quot;parent&quot;&gt;<br>  &lt;button id=&quot;child&quot;&gt;Click Me&lt;/button&gt;<br>&lt;/div&gt;</pre><pre>document<br>  .getElementById(&quot;parent&quot;)<br>  .addEventListener(&quot;click&quot;, () =&gt; {<br>    console.log(&quot;Parent Clicked&quot;);<br>  });</pre><pre>document<br>  .getElementById(&quot;child&quot;)<br>  .addEventListener(&quot;click&quot;, () =&gt; {<br>    console.log(&quot;Child Clicked&quot;);<br>  });</pre><p>Output:</p><pre>Child Clicked<br>Parent Clicked</pre><p>किन?</p><p>किनभने event button बाट parent तर्फ bubble भएको छ।</p><h3>Real Interview Question</h3><p><strong>Q: Why does a parent click event get triggered when clicking a child element?</strong></p><p><strong>Answer:</strong></p><p>Because when we click a child element, the event bubbles up to its parent elements. This is called <strong>Event Bubbling</strong>.stopPropagation()</p><p>Child ma click garda event Parent samma jancha. Yei process lai Event Bubbling bhanincha.</p><p>Production applications मा धेरैपटक bubbling रोक्नुपर्छ।</p><p>Example:</p><pre>button.addEventListener(&quot;click&quot;, (event) =&gt; {<br>  event.stopPropagation();<br>});</pre><h3>React Example</h3><pre>const handleButtonClick = (e) =&gt; {<br>  e.stopPropagation();<br>  console.log(&quot;Button Clicked&quot;);<br>};</pre><pre>return (<br>  &lt;div onClick={() =&gt; console.log(&quot;Card Clicked&quot;)}&gt;<br>    &lt;button onClick={handleButtonClick}&gt;<br>      Delete<br>    &lt;/button&gt;<br>  &lt;/div&gt;<br>);</pre><h3>Use Case</h3><h4>1. Imagine an E-commerce Product Card</h4><p>Yo card ma 2 ota actions chan:</p><ol><li><strong>Card Click:</strong> Product details page open huncha.</li><li><strong>Wishlist Button Click:</strong> Product wishlist ma add huncha.</li></ol><h4>2. What’s the problem?</h4><p>Maanau timile Wishlist button click garyau.</p><ul><li>Wishlist button ko event execute huncha.</li><li>Event bubble hudai parent Product Card samma pugcha.</li><li>Parent ko click event pani execute huncha.</li><li>Product details page pani open huncha.</li></ul><p><strong>But hamilai Wishlist matra add garnu cha, Product Details open garnu chaina.</strong></p><h4>3. How to solve it?</h4><p>event.stopPropagation() Use garne.</p><pre>const card = document.getElementById(&quot;card&quot;);<br>const wishlist = document.getElementById(&quot;wishlist&quot;);<br><br>card.addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Open Product Details&quot;);<br>});<br><br>wishlist.addEventListener(&quot;click&quot;, (event) =&gt; {<br>  event.stopPropagation();<br><br>  console.log(&quot;Added to Wishlist&quot;);<br>});</pre><h4>4. Output</h4><p><strong>When you click Product Card:</strong></p><p>Open Product Details</p><p><strong>When you click Wishlist Button:</strong></p><pre>Added to Wishlist</pre><p>Product Details open hudaina because stopPropagation() le event lai parent samma bubble huna didaina.</p><p>Wishlist button Product Card bhitra cha. Tesma click garda event bubble bhayera parent Card ko click event pani trigger huna sakcha.</p><p>stopPropagation() le tyo parent event trigger huna didaina.</p><h3>Event Capturing</h3><p>Capturing भनेको Bubbling को opposite हो।</p><p>Event root बाट target element सम्म जान्छ।</p><p>Event Capturing ma event sabai bhanda pahila Grandparent ma jancha, tespachi Parent hudai Child samma pugcha.</p><p>Flow:</p><pre>&lt;div id=&quot;grandparent&quot;&gt;<br>  Grandparent<br><br>  &lt;div id=&quot;parent&quot;&gt;<br>    Parent<br><br>    &lt;button id=&quot;child&quot;&gt;Click Me&lt;/button&gt;<br><br>  &lt;/div&gt;<br>&lt;/div&gt;<br><br><br>const grandparent = document.getElementById(&quot;grandparent&quot;);<br>const parent = document.getElementById(&quot;parent&quot;);<br>const child = document.getElementById(&quot;child&quot;);<br><br>grandparent.addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Grandparent clicked&quot;);<br>}, true);<br><br>parent.addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Parent clicked&quot;);<br>}, true);<br><br>child.addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Child clicked&quot;);<br>}, true);</pre><p><strong>Output (When you click the button):</strong></p><pre>Grandparent clicked<br>Parent clicked<br>Child clickedInterview Answer </pre><h4>3. What does true mean?</h4><pre>grandparent.addEventListener(&quot;click&quot;, callback, true);</pre><blockquote><em>Yo </em><em>true le event listener lai </em><strong><em>Capturing Phase</em></strong><em> ma execute gara bhanera specify garcha.</em></blockquote><ul><li>true = Event Capturing</li><li>false = Event Bubbling (default)</li></ul><blockquote><em>Event Capturing is the phase where an event travels from the root element down to the target element before reaching the target.</em></blockquote><p><strong>Q: What is the difference between Event Bubbling and Event Capturing?</strong></p><p><strong>Event Bubbling:</strong> The event moves from Child to Parent.</p><p><strong>Event Capturing:</strong> The event moves from Parent to Child.</p><ul><li>Bubbling: Child bata Parent tira jancha.</li><li>Capturing: Parent bata Child tira jancha.</li></ul><h3>Event Delegation</h3><p>Senior-level interviews मा अत्यधिक सोधिने topic।</p><p>Using one parent event listener to handle all child clicks.</p><p>Maanau timro parent bhitra 5 ota buttons chan. Sabai buttons ma separate event listener rakhnu bhanda parent ma euta matra event listener rakhne.</p><p>Parent le child buttons ko click handle garcha.</p><h3>2. Practical Example:</h3><pre>&lt;ul id=&quot;fruitList&quot;&gt;<br>  &lt;li&gt;Apple&lt;/li&gt;<br>  &lt;li&gt;Banana&lt;/li&gt;<br>  &lt;li&gt;Mango&lt;/li&gt;<br>  &lt;li&gt;Orange&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>Wrong Approach:</p><pre>const fruitList = document.getElementById(&quot;fruitList&quot;);<br><br>fruitList.addEventListener(&quot;click&quot;, (event) =&gt; {<br>  if (event.target.tagName === &quot;LI&quot;) {<br>    console.log(event.target.textContent);<br>  }<br>});</pre><p><strong>Output:</strong></p><ul><li>Apple click garda → Apple</li><li>Banana click garda → Banana</li><li>Mango click garda → Mango</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BbLZ2ek1eaY35I_slPZ8lg.png" /></figure><p><strong>Why use Event Delegation?</strong></p><ul><li>Fewer event listeners.</li><li>Easy to manage multiple child elements.</li><li>Works with dynamically added child elements too.</li></ul><p><strong>Q: What is Event Delegation in JavaScript?</strong></p><p>Event Delegation means adding one event listener to a parent element to handle events from its child elements.</p><p><strong>Nepali meaning:</strong> Dherai child elements ko event handle garna parent ma euta matra event listener rakhne process ho.</p><h4>Why Event Delegation?</h4><h4>Performance</h4><p>1000 elements</p><pre>1000 Listeners ❌<br>1 Listener ✅</pre><h4>Dynamic Elements Support</h4><pre>const li = document.createElement(&quot;li&quot;);<br>li.textContent = &quot;New User&quot;;</pre><pre>users.appendChild(li);</pre><p>New item automatically work गर्छ।</p><p>No extra listener required।</p><h3>React Interview Perspective</h3><p>React event delegation concept प्रयोग गर्छ । Internally</p><p>Older React versions:</p><pre>Document Level Event Delegation</pre><p>React 17+:</p><pre>Root Container Level Delegation</pre><p>React Synthetic Events ले browser inconsistencies handle गर्छ।</p><p>Example:</p><pre>&lt;button<br>  onClick={(e) =&gt; {<br>    console.log(e);<br>  }}<br>&gt;<br>  Click<br>&lt;/button&gt;</pre><p>यहाँ event वास्तवमा SyntheticEvent हो।</p><h3>Interview Question</h3><p><strong>Q: Does React use native DOM events?</strong></p><p>Answer:</p><blockquote><em>React wraps native browser events inside SyntheticEvent for cross-browser consistency and performance optimization.</em></blockquote><h3>Frequently Asked Interview Questions</h3><h3>Q1. Difference between Bubbling and Capturing?</h3><p>BubblingCapturingChild → ParentParent → ChildDefault BehaviorMust Enable Explicitly</p><h3>Q2. What is event.target?</h3><pre>console.log(event.target);</pre><p>Actual clicked element।</p><h3>Q3. What is event.currentTarget?</h3><pre>console.log(event.currentTarget);</pre><p>Element where listener is attached।</p><h3>Q4. Why use Event Delegation?</h3><ul><li>Better Performance</li><li>Less Memory Usage</li><li>Easier Maintenance</li><li>Supports Dynamic Elements</li></ul><h3>Q5. How does React handle events?</h3><p>React uses:</p><ul><li>Synthetic Events</li><li>Event Delegation</li><li>Root Container Event System</li></ul><h3>Final Thoughts</h3><p>React/Next.js Developer को रूपमा Event Propagation केवल interview topic मात्र होइन।</p><p>यसको knowledge ले:</p><ul><li>Complex UI Handling</li><li>Modal Management</li><li>Dropdown Components</li><li>Table Actions</li><li>Infinite Lists</li><li>Dynamic Components</li></ul><p>जस्ता production-level features build गर्दा धेरै help गर्छ।</p><p>यदि तपाईं React interview को तयारी गर्दै हुनुहुन्छ भने <strong>Event Bubbling, Capturing, stopPropagation(), event.target, event.currentTarget र Event Delegation</strong> यी ६ topics राम्रोसँग बुझ्नु अनिवार्य छ।</p><p><strong>Senior Frontend Interview Tip:</strong> Theory भन्दा बढी “real-world use cases” explain गर्न सक्नुभयो भने interview मा strong impression पर्छ।</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbf28a040a17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Control Flow and Error Handling — Complete Interview Preparation Guide ]]></title>
            <link>https://medium.com/@englishjha/javascript-control-flow-and-error-handling-complete-interview-preparation-guide-a3cc1c643075?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3cc1c643075</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Sun, 07 Jun 2026 05:18:46 GMT</pubDate>
            <atom:updated>2026-06-07T11:56:22.945Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>यदि तपाईं <strong>React.js, Next.js वा JavaScript Interview</strong> को तयारी गर्दै हुनुहुन्छ भने, एउटा topic जुन लगभग हरेक interview मा सोधिन्छ त्यो हो:</p><p><strong>Control Flow and Error Handling</strong></p><p>धेरै developers ले production मा feature develop गरिरहेका हुन्छन्, तर interview मा यस्ता प्रश्नहरू आउँदा confuse हुन्छन्:</p><blockquote><em>JavaScript ले कुन code execute गर्ने भनेर कसरी decide गर्छ?</em></blockquote><blockquote><em>API fail भयो भने application कसरी handle गर्ने?</em></blockquote><blockquote><em>throw, try/catch र finally बीच difference के हो?</em></blockquote><p>Interviewer ले यी questions syntax check गर्न मात्र सोधेको हुँदैन।</p><p>उनीहरूले evaluate गरिरहेका हुन्छन्:</p><ul><li>Problem Solving Skill</li><li>Debugging Capability</li><li>Production Experience</li><li>JavaScript Fundamentals</li><li>Error Handling Mindset</li></ul><h3>Real Interview Scenario</h3><p>मानौं तपाईं Product-Based Company को interview दिइरहनुभएको छ।</p><p>Interviewer ले सोध्यो:</p><blockquote><em>“Production मा API suddenly fail भयो र users लाई white screen देखिन थाल्यो भने तपाईं कसरी handle गर्नुहुन्छ?”</em></blockquote><p>धेरै candidates ले तुरुन्तै Axios वा Fetch को कुरा गर्न थाल्छन्।</p><p>तर senior engineers ले पहिले discuss गर्छन्:</p><ul><li>Control Flow</li><li>Error Propagation</li><li>Exception Handling</li><li>Recovery Strategy</li></ul><p>यही कारणले <strong>JavaScript Control Flow and Error Handling</strong> Frontend Interview Guide को अत्यन्त important topic हो।</p><h3>What is JavaScript Control Flow?</h3><p>Simple भाषामा भन्नुपर्दा:</p><p><strong>JavaScript ले कुन code कहिले run गर्ने र कुन condition मा run गर्ने भन्ने process लाई Control Flow भनिन्छ।</strong></p><p>JavaScript ले decide गर्छ:</p><ul><li>कुन statement execute गर्ने</li><li>कुन statement skip गर्ने</li><li>कुन condition true हुँदा next step मा जाने</li></ul><h3>Real Life Example</h3><p>मानौं तपाईं बिहान office जान लाग्नुभएको छ।</p><pre>Wake Up<br>   |<br>   v<br>Rain Check<br>   |<br>Yes ------&gt; Take Umbrella<br>   |<br>No<br>   |<br>Go Office</pre><p>यहाँ तपाईंले एउटा decision लिनुभयो।</p><p>यही decision making process लाई programming मा Control Flow भनिन्छ।</p><p>JavaScript पनि यही principle मा काम गर्छ।</p><pre>const isRaining = true;</pre><pre>if (isRaining) {<br>  console.log(&quot;Take Umbrella&quot;);<br>}</pre><h3>Output</h3><pre>Take Umbrella</pre><h3>🔥 Interview Question</h3><p>What is Control Flow in JavaScript?</p><h3>✅ Expected Answer</h3><blockquote><em>“Control Flow भन्नाले JavaScript engine ले program को execution order manage गर्ने process हो। Conditions, loops, functions र exception handling प्रयोग गरेर execution path control गरिन्छ।”</em></blockquote><h3>💡 Pro Tip</h3><p>Definition मात्र नदिनुहोस्।</p><p>Answer Structure:</p><pre>Definition<br>↓<br>Simple Example<br>↓<br>Real Project Example</pre><h3>Block Statement</h3><p>Block Statement भनेको multiple statements लाई एउटा group भित्र राख्ने तरिका हो।</p><p>JavaScript मा curly braces {} प्रयोग गरेर block create गरिन्छ।</p><pre>{<br>  statement1;<br>  statement2;<br>}</pre><h3>Example</h3><pre>if (true) {<br>  console.log(&quot;Hello&quot;);<br>  console.log(&quot;World&quot;);<br>}</pre><h3>Output</h3><pre>Hello<br>World</pre><h3>var vs let vs const</h3><p>Interview मा धेरै पटक सोधिने question।</p><h3>var Example</h3><pre>{<br>  var name = &quot;Sachin&quot;;<br>}</pre><pre>console.log(name);</pre><h3>Output</h3><pre>Sachin</pre><p>किन?</p><p>किनभने <strong>var function-scoped</strong> हुन्छ।</p><p>Block बाहिर पनि access गर्न सकिन्छ।</p><h3>let Example</h3><pre>{<br>  let name = &quot;Sachin&quot;;<br>}</pre><pre>console.log(name);</pre><h3>Output</h3><pre>ReferenceError</pre><p>किनकि <strong>let block-scoped</strong> हुन्छ।</p><h3>const Example</h3><pre>{<br>  const name = &quot;Sachin&quot;;<br>}</pre><pre>console.log(name);</pre><h3>Output</h3><pre>ReferenceError</pre><h3>🔥 Interview Question</h3><p>Why is let preferred over var?</p><h3>✅ Expected Answer</h3><blockquote><em>“let block-scoped हुन्छ जसले accidental variable access रोक्छ। यसले scope-related bugs कम गर्छ र code maintain गर्न सजिलो बनाउँछ।”</em></blockquote><h3>💡 Pro Tip</h3><p>Answer गर्दा यी keywords प्रयोग गर्नुहोस्:</p><ul><li>Block Scope</li><li>Hoisting</li><li>Temporal Dead Zone</li></ul><p>Interviewer प्रभावित हुन्छ।</p><h3>Conditional Statements</h3><p>Conditional Statements प्रयोग गरेर JavaScript ले decision लिन्छ।</p><p>मुख्यत:</p><ul><li>if</li><li>if else</li><li>else if</li><li>nested if</li><li>switch</li></ul><h3>if Statement</h3><p>यदि एउटा condition मात्र check गर्नुपर्ने छ भने if use गरिन्छ।</p><pre>const score = 80;</pre><pre>if (score &gt;= 50) {<br>  console.log(&quot;Pass&quot;);<br>}</pre><h3>Output</h3><pre>Pass</pre><h3>Real Project Example</h3><pre>if (user.isLoggedIn) {<br>  showDashboard();<br>}</pre><p>User login छ भने dashboard देखाउने।</p><p>नत्र login page।</p><h3>🔥 Interview Question</h3><p>When should you use if?</p><h3>✅ Expected Answer</h3><blockquote><em>“जब एउटा single condition check गर्नुपर्ने हुन्छ तब if statement use गरिन्छ।”</em></blockquote><pre>if...else<br>const age = 15;<br><br>if (age &gt;= 18) {<br>  console.log(&quot;Adult&quot;);<br>} else {<br>  console.log(&quot;Minor&quot;);<br>}<br>Output<br>Minor</pre><pre>else if<br>const marks = 85;<br><br>if (marks &gt;= 90) {<br>  console.log(&quot;A&quot;);<br>} else if (marks &gt;= 75) {<br>  console.log(&quot;B&quot;);<br>} else {<br>  console.log(&quot;C&quot;);<br>}<br>Output<br>B</pre><pre>Nested if<br>const isLoggedIn = true;<br>const isAdmin = true;<br><br>if (isLoggedIn) {<br>  if (isAdmin) {<br>    console.log(&quot;Admin Panel&quot;);<br>  }<br>}<br>Output<br>Admin Panel</pre><h3>Best Practices</h3><p>❌ Avoid deep nesting</p><pre>if(a){<br> if(b){<br>  if(c){<br>  }<br> }<br>}</pre><p>✅ Use early returns</p><pre>if (!user) return;<br>if (!user.isAdmin) return;</pre><h3>🔥 Interview Question</h3><p>Why avoid deeply nested if statements?</p><h3>✅ Expected Answer</h3><p>They reduce readability and increase maintenance complexity.</p><h3>💡 Pro Tip</h3><p>Mention early return pattern.</p><h3>Truthy vs Falsy Values</h3><p>यो topic Amazon, Adobe, Leapfrog, Cotiviti, F1Soft लगायत धेरै company interview मा आउँछ।</p><h3>JavaScript मा Falsy Values</h3><p>केवल यी values falsy हुन्छन्:</p><p><strong>Falsy</strong> <strong>Values</strong></p><pre><br><br>Only 7 values are falsy:<br><br>Value<br>false<br>0<br>-0<br>&quot;&quot;<br>null<br>undefined<br>NaN</pre><p>Example</p><pre>if (&quot;&quot;) {<br>  console.log(&quot;Hello&quot;);<br>}</pre><h3>Output</h3><p>Nothing</p><h3>Truthy Values</h3><p>Everything else is truthy.</p><pre>if (&quot;hello&quot;) {<br>  console.log(&quot;Truthy&quot;);<br>}</pre><h3>Output</h3><pre>Truthy</pre><p>बाकी सबै values truthy हुन्छन्।</p><h3>Common Interview Trap</h3><pre>if ([]) {<br>  console.log(&quot;Hello&quot;);<br>}<br><br>Output<br>True<br><br>Array is truthy.<br><br><br>if ({}) {<br>  console.log(&quot;True&quot;);<br>}<br>Output<br>True<br><br>Object is truthy.</pre><p>धेरै developers ले false भन्छन्।</p><p>तर answer हो:</p><p>✅ True</p><p>किनकि Empty Array पनि Object हो।</p><p>र JavaScript मा सबै Objects truthy हुन्छन्।</p><h3>🔥 Interview Question</h3><p>Is an empty array truthy or falsy?</p><h3>✅ Expected Answer</h3><blockquote><em>“Empty array truthy हुन्छ किनकि JavaScript मा सबै objects truthy मानिन्छन्।”</em></blockquote><h3>💡 Pro Tip</h3><p>Interview मा धेरै पटक सोधिने question हो।</p><h3>Switch Statement</h3><p>Used when multiple conditions depend on one value.</p><h3>Syntax</h3><pre>switch(expression){<br> case value:<br>   break;<br>default:<br>}</pre><h3>Example</h3><pre>const role = &quot;admin&quot;;</pre><pre>switch (role) {<br>  case &quot;admin&quot;:<br>    console.log(&quot;Admin Panel&quot;);<br>    break;</pre><pre>  case &quot;user&quot;:<br>    console.log(&quot;User Panel&quot;);<br>    break;</pre><pre>  default:<br>    console.log(&quot;Guest&quot;);<br>}</pre><h3>Output</h3><pre>Admin Panel</pre><h3>break Keyword</h3><p>Without break:</p><pre>const day = 1;</pre><pre>switch(day){<br> case 1:<br>   console.log(&quot;Mon&quot;);</pre><pre> case 2:<br>   console.log(&quot;Tue&quot;);<br>}</pre><h3>Output</h3><pre>Mon<br>Tue</pre><p>This is called <strong>Fallthrough</strong>.</p><h3>Real Project Example</h3><pre>switch(apiStatus){<br> case &quot;loading&quot;:<br>   return &lt;Loader /&gt;<br>case &quot;success&quot;:<br>   return &lt;Data /&gt;<br> case &quot;error&quot;:<br>   return &lt;Error /&gt;<br>}</pre><p>React projects मा यस्तो pattern धेरै use हुन्छ।</p><h3>🔥 Interview Question</h3><p>What happens if break is omitted?</p><h3>✅ Expected Answer</h3><p>Execution continues into the next case block.</p><h3>💡 Pro Tip</h3><p>Use the term “fallthrough.”</p><h3>Error Handling in JavaScript</h3><p>Production application मा error आउँदैन भन्ने guarantee हुँदैन।</p><p>Errors आउन सक्छ:</p><ul><li>API Failure</li><li>Network Issue</li><li>Invalid Input</li><li>Server Crash</li><li>Business Logic Bug</li></ul><p>यदि proper Error Handling छैन भने:</p><p>❌ White Screen</p><p>❌ Application Crash</p><p>❌ Bad User Experience</p><h3>Real Production Example</h3><pre>const data = await fetch(&quot;/users&quot;);</pre><p>What if API fails?</p><p>Without error handling:</p><pre>Unhandled Promise Rejection</pre><h3>throw Statement</h3><p>throw keyword प्रयोग गरेर custom error create गर्न सकिन्छ।</p><h3>Syntax</h3><pre>throw expression;</pre><pre>const age = 15;<br><br>if (age &lt; 18) {<br>  throw new Error(&quot;Age must be 18+&quot;);<br>}</pre><h3>Output</h3><pre>Error: Age must be 18+</pre><h3>Custom Validation</h3><pre>function registerUser(age) {<br>  if (age &lt; 18) {<br>    throw new Error(&quot;Invalid Age&quot;);<br>  }<br>}</pre><h3>🔥 Interview Question</h3><p>Why use throw?</p><h3>✅ Expected Answer</h3><blockquote><em>“Business validation fail हुँदा custom exception generate गर्न throw प्रयोग गरिन्छ।”</em></blockquote><h4>💡 Pro Tip</h4><p>Always throw Error objects instead of strings.</p><h3>try…catch</h3><p>JavaScript Error Handling को backbone नै try…catch हो</p><pre>try {  } catch(error) {  }</pre><h3>Example</h3><pre>try {<br>  JSON.parse(&quot;abc&quot;);<br>}<br>catch(error){<br>  console.log(error.message);<br>}</pre><h3>Output</h3><pre>Unexpected token a</pre><h3>Execution Flow</h3><pre>Try Block<br>    |<br>Success?<br> /     \<br>Yes     No<br> |       |<br>Continue Catch</pre><h4>API Integration Example</h4><pre>try { const response = await fetch(&quot;/users&quot;); const data = await response.json(); console.log(data); } catch(error) { console.log(&quot;API Failed&quot;); }</pre><h3>React Real World Example</h3><pre>useEffect(() =&gt; { <br>async function loadUsers(){</pre><pre>   try{</pre><pre>     const response = await fetch(&quot;/api/users&quot;);</pre><pre>     const data = await response.json();</pre><pre>     setUsers(data);</pre><pre>   }catch(error){</pre><pre>     setError(error.message);</pre><pre>   }</pre><pre> }</pre><pre> loadUsers();</pre><pre>},[]);</pre><p>React application मा यो pattern अत्यन्त common छ।</p><h3>Next.js Example</h3><pre>export async function getServerSideProps() { </pre><pre>try {</pre><pre>   const response = await fetch(API_URL);</pre><pre>   const data = await response.json();</pre><pre>   return {<br>     props:{data}<br>   };</pre><pre> } catch(error){</pre><pre>   return {<br>      notFound:true<br>   };</pre><pre> }</pre><pre>}</pre><h3>🔥 Interview Question</h3><p>Difference between throw and try/catch?</p><h3>✅ Expected Answer</h3><blockquote><em>“throw ले exception create गर्छ भने try/catch ले त्यस exception लाई handle गर्छ।”</em></blockquote><h3>💡 Pro Tip</h3><p>Mention exception propagation.</p><h3>React &amp; Next.js Real World Error Handling</h3><h3>Fetch API</h3><pre>try { <br>const response = await fetch(API);</pre><pre> if(!response.ok){<br>   throw new Error(&quot;Request Failed&quot;);<br> }</pre><pre> const data = await response.json();</pre><pre>}<br>catch(error){</pre><pre> console.error(error);</pre><pre>}</pre><h3>Axios Example</h3><pre>try { <br>const {data} = await axios.get(&quot;/users&quot;);</pre><pre>}<br>catch(error){</pre><pre> console.log(error.response);</pre><pre>}</pre><h3>Async Await Error Handling</h3><pre>async function getUsers(){<br> try{</pre><pre>   const users = await apiCall();</pre><pre>   return users;</pre><pre> }catch(error){</pre><pre>   return [];</pre><pre> }</pre><pre>}</pre><h3>Error Boundary</h3><p>React Error Boundary catches UI rendering errors.</p><pre>class ErrorBoundary extends React.Component { <br>state = {<br>   hasError:false<br> };</pre><pre> static getDerivedStateFromError(){<br>   return {<br>      hasError:true<br>   };<br> }</pre><pre> render(){</pre><pre>  if(this.state.hasError){<br>    return &lt;h1&gt;Something Went Wrong&lt;/h1&gt;;<br>  }</pre><pre>  return this.props.children;<br> }<br>}</pre><h3>Production Best Practices</h3><p>✅ Never show raw errors</p><p>✅ Log to monitoring tools</p><p>✅ Create reusable error handlers</p><p>✅ Handle API status codes</p><p>✅ Provide fallback UI</p><h3>15 Most Asked JavaScript Interview Questions</h3><h3>1. What is Control Flow?</h3><p><strong>Answer:</strong> Execution order of statements.</p><h3>2. Difference between if and switch?</h3><p><strong>Answer:</strong> switch is cleaner for multiple fixed values.</p><h3>3. What are falsy values?</h3><p><strong>Answer:</strong> false, 0, -0, “”, null, undefined, NaN.</p><h3>4. Is [] truthy?</h3><p><strong>Answer:</strong> Yes.</p><h3>5. Is {} truthy?</h3><p><strong>Answer:</strong> Yes.</p><h3>6. What is throw?</h3><p><strong>Answer:</strong> Creates an exception.</p><h3>7. Difference between Error and Exception?</h3><p><strong>Answer:</strong> Exception is the event. Error is the object.</p><h3>8. Why use try/catch?</h3><p><strong>Answer:</strong> To handle runtime errors gracefully.</p><h3>9. What does finally do?</h3><p><strong>Answer:</strong> Executes regardless of success/failure.</p><h3>10. Does finally execute after return?</h3><p><strong>Answer:</strong> Yes.</p><h3>11. Can we throw strings?</h3><p><strong>Answer:</strong> Yes, but not recommended.</p><h3>12. Why use Error objects?</h3><p><strong>Answer:</strong> Better debugging support.</p><h3>13. What is Error Boundary?</h3><p><strong>Answer:</strong> React component for catching rendering errors.</p><h3>14. How do you handle API failures?</h3><p><strong>Answer:</strong> try/catch + fallback UI + logging.</p><h3>15. Difference between synchronous and asynchronous error handling?</h3><p><strong>Answer:</strong> Async errors usually require Promise handling or async/await with try/catch.</p><h3>FAANG-Level Tricky Questions</h3><h3>Question 1</h3><pre>try {<br>  return 1;<br>}<br>finally {<br>  return 2;<br>}</pre><h3>Output</h3><pre>2</pre><p>finally overrides return.</p><h3>Question 2</h3><pre>if([]){<br> console.log(&quot;Hello&quot;);<br>}</pre><h3>Output</h3><pre>Hello</pre><h3>Question 3</h3><pre>if({}){<br> console.log(&quot;World&quot;);<br>}</pre><h3>Output</h3><pre>World</pre><h3>Question 4</h3><pre>switch(1){<br> case &quot;1&quot;:<br>   console.log(&quot;A&quot;);<br> break;</pre><pre> case 1:<br>   console.log(&quot;B&quot;);<br>}</pre><h3>Output</h3><pre>B</pre><p>Strict comparison used.</p><h3>Question 5</h3><pre>try{<br> throw new Error(&quot;X&quot;);<br>}<br>catch(e){<br> console.log(e.message);<br>}</pre><h3>Output</h3><pre>X</pre><h3>Senior Developer Insights</h3><p>After taking hundreds of interviews, here’s what interviewers actually expect.</p><h3>They Don’t Care About Memorization</h3><p>They care about:</p><ul><li>Problem solving</li><li>Debugging</li><li>Real-world thinking</li><li>Production experience</li></ul><h3>Common Candidate Mistakes</h3><h3>Mistake #1</h3><p>Explaining syntax only.</p><h3>Mistake #2</h3><p>No production examples.</p><h3>Mistake #3</h3><p>Ignoring edge cases.</p><h3>Mistake #4</h3><p>Confusing truthy and falsy values.</p><h3>Mistake #5</h3><p>Not understanding error propagation.</p><h3>How to Answer Confidently</h3><p>Follow this structure:</p><pre>Definition<br>↓<br>Why Needed<br>↓<br>Example<br>↓<br>Production Use Case<br>↓<br>Best Practice</pre><p>This structure instantly makes you sound like a senior engineer.</p><h3>Summary &amp; Key Takeaways</h3><h3>JavaScript Control Flow</h3><ul><li>Controls execution order</li><li>Uses blocks and conditions</li><li>Enables decision making</li></ul><h3>Conditional Statements</h3><ul><li>if</li><li>if else</li><li>else if</li><li>nested if</li><li>switch</li></ul><h3>Truthy/Falsy</h3><p>Remember the 7 falsy values.</p><h3>JavaScript Error Handling</h3><ul><li>throw</li><li>try</li><li>catch</li><li>finally</li><li>Error Object</li></ul><h3>React &amp; Next.js</h3><ul><li>Handle API failures</li><li>Use async/await with try/catch</li><li>Implement Error Boundaries</li><li>Show fallback UI</li></ul><h3>Final Interview Checklist ✅</h3><p>Before attending your next React.js, Next.js, or JavaScript interview, ensure you can confidently explain:</p><ul><li>Block Scope</li><li>var vs let vs const</li><li>if vs switch</li><li>Truthy vs Falsy</li><li>throw Statement</li><li>try/catch/finally</li><li>Error Object</li><li>Custom Errors</li><li>Async Error Handling</li><li>Fetch &amp; Axios Error Handling</li><li>React Error Boundaries</li><li>Next.js Error Strategies</li></ul><p>Master these topics and you’ll be significantly more prepared for <strong>JavaScript Interview Questions</strong>, <strong>React Interview Preparation</strong>, and <strong>FAANG-level Frontend Interviews</strong>. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3cc1c643075" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How JavaScript Works Behind the Scenes ]]></title>
            <link>https://medium.com/@englishjha/how-javascript-works-behind-the-scenes-b4bba97cfa20?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4bba97cfa20</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 17:46:23 GMT</pubDate>
            <atom:updated>2026-06-02T17:46:23.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>यदि तपाईं Frontend Developer हुनुहुन्छ भने JavaScript केवल syntax सिकेर मात्र पुग्दैन। Real project मा performance issue, debugging problem, memory leak, asynchronous behavior, optimization, र scalability जस्ता challenges आउँछन्। त्यस्ता समस्या solve गर्न JavaScript internally कसरी काम गर्छ भन्ने बुझ्नु अत्यन्तै महत्वपूर्ण हुन्छ।</p><p>Frontend developer को perspective बाट हेर्दा, React, Next.js, Vue, Angular वा कुनै पनि framework प्रयोग गरे पनि अन्ततः browser ले execute गर्ने JavaScript नै हो। त्यसैले JavaScript engine, Call Stack, Event Loop, Memory Management, Hoisting लगायतका concepts राम्रोसँग बुझ्नु developer growth को लागि आवश्यक छ।</p><p>यस article मा हामी JavaScript को internals लाई practical examples सहित सरल भाषामा बुझ्ने प्रयास गर्नेछौं।</p><h3>Evolution of JavaScript</h3><p>JavaScript को जन्म 1995 मा Brendan Eich द्वारा Netscape मा भएको थियो। सुरुमा केवल browser interaction को लागि बनाइएको language आज full-stack ecosystem को backbone बनेको छ।</p><h3>Important Milestones</h3><ul><li>ES3 (1999) → Regular Expressions, Error Handling</li><li>ES5 (2009) → Strict Mode, JSON Support</li><li>ES6 (2015) → let, const, Arrow Functions, Classes, Modules</li><li>ES2020+ → Optional Chaining, Nullish Coalescing, BigInt</li><li>ES2024 → More performance and language improvements</li></ul><p>Real project मा हामीले प्रयोग गर्ने अधिकांश modern syntax ES6 पछि आएको हो।</p><h3>JavaScript Engine (V8)</h3><p>JavaScript लाई execute गर्ने काम JavaScript Engine ले गर्छ।</p><p>Popular Engines:</p><ul><li>V8 (Chrome &amp; Node.js)</li><li>SpiderMonkey (Firefox)</li><li>JavaScriptCore (Safari)</li></ul><h3>V8 Engine Flow</h3><pre>JavaScript Code<br>       ↓<br>     Parser<br>       ↓<br>      AST<br>       ↓<br>   Compiler<br>       ↓<br> Bytecode/Machine Code<br>       ↓<br>    Execution</pre><p>Browser मा code लेखेपछि सीधै execute हुँदैन। Engine ले पहिला parse गर्छ, compile गर्छ अनि execute गर्छ।</p><h3>Parsing, Compilation &amp; Execution</h3><p>जब browser ले JavaScript file load गर्छ:</p><h3>1. Parsing</h3><pre>const name = &quot;Sachin&quot;;</pre><p>Engine ले syntax valid छ कि छैन भनेर check गर्छ।</p><h3>2. Compilation</h3><p>Code लाई bytecode मा convert गरिन्छ।</p><h3>3. Execution</h3><p>Bytecode execute हुन्छ।</p><p>Practical scenario मा syntax error आएमा code execution सुरु नै हुँदैन।</p><h3>Execution Context</h3><p>JavaScript मा code execution को लागि Execution Context create हुन्छ।</p><p>Types:</p><ol><li>Global Execution Context</li><li>Function Execution Context</li></ol><p>Example:</p><pre>var name = &quot;Sachin&quot;;</pre><pre>function greet() {<br>  console.log(&quot;Hello&quot;);<br>}</pre><pre>greet();</pre><p>Execution Flow:</p><pre>Global Context<br>      ↓<br>Function Context<br>      ↓<br>Return<br>      ↓<br>Global Context</pre><p>Interview मा धेरै सोधिने question हो Execution Context के हो भनेर।</p><h3>Call Stack</h3><p>Call Stack एउटा LIFO (Last In First Out) data structure हो।</p><p>Example:</p><pre>function first() {<br>  second();<br>}</pre><pre>function second() {<br>  console.log(&quot;Second&quot;);<br>}</pre><pre>first();</pre><p>Stack Visualization:</p><pre>Call Stack</pre><pre>second()<br>first()<br>Global()</pre><p>Execution पछि:</p><pre>Global()</pre><p>Real project मा “Maximum Call Stack Size Exceeded” error recursion गलत हुँदा देखिन्छ।</p><h3>Event Loop</h3><p>JavaScript Single Threaded language हो।</p><p>एक समयमा एउटा काम मात्र execute गर्न सक्छ।</p><p>तर API calls, timers, file operations जस्ता asynchronous task हरू कसरी handle गर्छ?</p><p>उत्तर हो Event Loop।</p><pre>Call Stack<br>     ↓<br> Event Loop<br>     ↓<br>Task Queues</pre><p>Event Loop लगातार check गरिरहेको हुन्छ:</p><p>“Call Stack खाली भयो कि भएन?”</p><p>खाली भए task queue बाट काम execute हुन्छ।</p><h3>Callback Queue &amp; Microtask Queue</h3><p>Interview मा धेरै सोधिने question मध्ये यो एकदमै popular topic हो।</p><p>Example:</p><pre>console.log(&quot;Start&quot;);</pre><pre>setTimeout(() =&gt; {<br>  console.log(&quot;Timeout&quot;);<br>}, 0);</pre><pre>Promise.resolve().then(() =&gt; {<br>  console.log(&quot;Promise&quot;);<br>});</pre><pre>console.log(&quot;End&quot;);</pre><p>Output:</p><pre>Start<br>End<br>Promise<br>Timeout</pre><p>Why?</p><pre>Microtask Queue<br>     ↑<br> Higher Priority</pre><pre>Callback Queue<br>     ↓<br> Lower Priority</pre><p>Promise → Microtask Queue</p><p>setTimeout → Callback Queue</p><p>त्यसैले Promise पहिले execute हुन्छ।</p><h3>Memory Management</h3><p>JavaScript automatically memory manage गर्छ।</p><h3>Stack Memory</h3><p>Primitive Data:</p><pre>let age = 25;<br>let name = &quot;Sachin&quot;;</pre><h3>Heap Memory</h3><p>Objects &amp; Arrays:</p><pre>const user = {<br>  name: &quot;Sachin&quot;<br>};</pre><p>Visualization:</p><pre>Stack<br> ↓<br>Reference</pre><pre>Heap<br> ↓<br>Actual Object</pre><h3>Garbage Collection</h3><p>Unused memory automatically remove गरिन्छ।</p><p>Example:</p><pre>let user = {<br>  name: &quot;Sachin&quot;<br>};</pre><pre>user = null;</pre><p>अब object को reference हरायो।</p><p>Garbage Collector ले memory free गर्छ।</p><p>Real project मा memory leak avoid गर्न event listeners remove गर्नुपर्छ।</p><h3>Hoisting</h3><p>Hoisting भनेको declaration लाई scope को top मा move गरेको जस्तो behavior हो।</p><p>Example:</p><pre>console.log(name);</pre><pre>var name = &quot;Sachin&quot;;</pre><p>Output:</p><pre>undefined</pre><p>Because:</p><pre>var name;<br>console.log(name);</pre><pre>name = &quot;Sachin&quot;;</pre><h3>let &amp; const</h3><pre>console.log(age);</pre><pre>let age = 20;</pre><p>Output:</p><pre>ReferenceError</pre><p>कारण:</p><p>Temporal Dead Zone (TDZ)</p><h3>Promises in JavaScript</h3><p>Promise asynchronous operation handle गर्न प्रयोग हुन्छ।</p><p>States:</p><ul><li>Pending</li><li>Fulfilled</li><li>Rejected</li></ul><p>Example:</p><pre>const promise = new Promise((resolve) =&gt; {<br>  setTimeout(() =&gt; {<br>    resolve(&quot;Data Loaded&quot;);<br>  }, 1000);<br>});</pre><pre>promise.then((data) =&gt; {<br>  console.log(data);<br>});</pre><p>Output:</p><pre>Data Loaded</pre><h3>Async/Await</h3><p>Promise भन्दा readable syntax।</p><p>Example:</p><pre>async function fetchData() {<br>  const response = await fetch(&quot;/api/users&quot;);</pre><pre>  const data = await response.json();</pre><pre>  console.log(data);<br>}</pre><pre>fetchData();</pre><p>Real project मा API integration गर्दा Async/Await सबैभन्दा बढी प्रयोग हुन्छ।</p><h3>Node.js Runtime</h3><p>Node.js ले JavaScript लाई browser बाहिर चलाउन दिन्छ।</p><p>Benefits:</p><ul><li>Backend Development</li><li>File System Access</li><li>HTTP Server</li><li>Database Connectivity</li></ul><p>Example:</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>fs.readFile(&quot;test.txt&quot;, &quot;utf8&quot;, (err, data) =&gt; {<br>  console.log(data);<br>});</pre><p>Frontend developer को perspective बाट React + Next.js + Node ecosystem अहिले industry standard जस्तै भइसकेको छ।</p><h3>Prototypal Inheritance</h3><p>JavaScript Class-based होइन, Prototype-based language हो।</p><p>Example:</p><pre>function Person(name) {<br>  this.name = name;<br>}</pre><pre>Person.prototype.greet = function () {<br>  console.log(`Hello ${this.name}`);<br>};</pre><pre>const user = new Person(&quot;Sachin&quot;);</pre><pre>user.greet();</pre><p>Output:</p><pre>Hello Sachin</pre><p>Benefits:</p><ul><li>Memory Efficient</li><li>Shared Methods</li><li>Better Performance</li></ul><h3>JIT Compilation</h3><p>Modern engines JIT (Just In Time) Compilation प्रयोग गर्छन्।</p><p>Process:</p><pre>Code<br> ↓<br>Parser<br> ↓<br>Bytecode<br> ↓<br>Frequently Used?<br> ↓<br>Optimized Machine Code</pre><p>Example:</p><pre>function add(a, b) {<br>  return a + b;<br>}</pre><pre>for(let i = 0; i &lt; 1000000; i++) {<br>  add(10, 20);<br>}</pre><p>Repeated execution हुँदा V8 ले optimize गर्छ।</p><p>यसले performance significantly improve गर्छ।</p><h3>ES6 Modules</h3><p>Large project मा modules अत्यन्तै महत्वपूर्ण हुन्छन्।</p><h3>Export</h3><pre>export function add(a, b) {<br>  return a + b;<br>}</pre><h3>Import</h3><pre>import { add } from &quot;./utils.js&quot;;</pre><pre>console.log(add(10, 20));</pre><p>Benefits:</p><ul><li>Code Reusability</li><li>Better Maintainability</li><li>Scalability</li></ul><h3>Scope in JavaScript</h3><h3>Global Scope</h3><pre>var company = &quot;Google&quot;;</pre><p>जहाँबाट पनि access गर्न सकिन्छ।</p><h3>Function Scope</h3><pre>function test() {<br>  var message = &quot;Hello&quot;;<br>}</pre><p>Function बाहिर access गर्न मिल्दैन।</p><h3>Block Scope</h3><pre>if(true){<br>  let age = 25;<br>}</pre><p>Block बाहिर access गर्दा error आउँछ।</p><p>Modern JavaScript मा let र const प्रयोग गर्नु best practice हो।</p><h3>Performance Tips</h3><h3>✅ Use let &amp; const</h3><pre>const API_URL = &quot;...&quot;;</pre><h3>✅ Avoid Global Variables</h3><p>Global namespace pollution हुन्छ।</p><h3>✅ Debounce API Calls</h3><p>Search functionality मा अत्यन्त useful।</p><h3>✅ Lazy Loading</h3><p>Large application faster बनाउँछ।</p><h3>✅ Event Delegation</h3><p>Multiple listeners भन्दा efficient।</p><h3>Common Mistakes Developers Make</h3><h3>❌ Using var everywhere</h3><pre>var name = &quot;test&quot;;</pre><h3>❌ Callback Hell</h3><pre>api1(()=&gt;{<br> api2(()=&gt;{<br>   api3(()=&gt;{<br>   })<br> })<br>})</pre><h3>❌ Memory Leaks</h3><p>Event listeners remove नगर्नु।</p><h3>❌ Ignoring Promise Errors</h3><pre>fetchData()<br>.catch(error =&gt; {<br>  console.error(error);<br>});</pre><h3>Interview Questions &amp; Answers</h3><h3>Q1. JavaScript Single Threaded किन भनिन्छ?</h3><p>JavaScript एक समयमा एउटा operation मात्र execute गर्न सक्छ।</p><h3>Q2. Event Loop के हो?</h3><p>Call Stack खाली भएपछि queued tasks execute गर्ने mechanism हो।</p><h3>Q3. Promise र Callback बीच फरक के हो?</h3><p>Promise cleaner, readable र chainable हुन्छ।</p><h3>Q4. Hoisting के हो?</h3><p>Variable/function declarations execution अघि process हुने behavior हो।</p><h3>Q5. let र var बीच फरक?</h3><p>let block-scoped हुन्छ, var function-scoped हुन्छ।</p><h3>Key Takeaways</h3><p>✅ JavaScript Single Threaded Language हो</p><p>✅ V8 Engine ले code parse, compile र execute गर्छ</p><p>✅ Call Stack function execution manage गर्छ</p><p>✅ Event Loop asynchronous tasks handle गर्छ</p><p>✅ Promise Microtask Queue मा जान्छ</p><p>✅ Objects Heap मा store हुन्छन्</p><p>✅ Garbage Collection memory manage गर्छ</p><p>✅ Async/Await modern asynchronous approach हो</p><p>✅ Modules large project architecture को foundation हुन्</p><p>✅ Scope बुझ्नु clean code लेख्न अत्यन्त महत्वपूर्ण छ</p><h3>Conclusion</h3><p>JavaScript को syntax मात्र जान्नु र JavaScript वास्तवमै कसरी काम गर्छ भन्ने बुझ्नु बीच ठूलो फरक छ। Real project मा performance issue, unexpected bugs, memory leaks, API handling, rendering optimization जस्ता समस्या solve गर्न JavaScript internals को knowledge अत्यन्तै valuable हुन्छ।</p><p>मेरो 5+ वर्षको development experience अनुसार, Event Loop, Execution Context, Call Stack, Hoisting, Scope, Promise र Memory Management जस्ता concepts राम्रोसँग बुझेपछि debugging speed dramatically improve हुन्छ। React, Next.js, Node.js वा कुनै पनि modern framework प्रयोग गरे पनि अन्ततः browser ले execute गर्ने JavaScript नै हो।</p><p>त्यसैले यदि तपाईं Junior बाट Mid-Level वा Senior Developer बन्न चाहनुहुन्छ भने JavaScript को behind-the-scenes working mechanism बुझ्नु optional होइन, अनिवार्य skill हो।</p><p>Happy Coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4bba97cfa20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Memory Management (Stack vs Heap) ]]></title>
            <link>https://medium.com/@englishjha/javascript-memory-management-stack-vs-heap-9680976c1828?source=rss-6404dec94b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9680976c1828</guid>
            <dc:creator><![CDATA[Englishjha]]></dc:creator>
            <pubDate>Sun, 31 May 2026 14:20:50 GMT</pubDate>
            <atom:updated>2026-06-09T18:21:33.599Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript ma memory management automatically handle hunxa.<br> Hami manually malloc() , free() jasto kaam gardainau jasto C language ma hunxa.<br> JavaScript engine le memory allocate ra free automatically garxa using <strong>Garbage Collection (GC)</strong>.</p><h4><strong>Memory Types in JavaScript</strong></h4><p>JavaScript ma mainly 2 type ko memory use hunxa:</p><ol><li><strong>Stack Memory (Primitive Types)</strong></li><li><strong>Heap Memory (Non-Primitive / Reference Types)</strong></li></ol><h4>1. Stack Memory (Primitive)</h4><p>Primitive data types:</p><ul><li>String</li><li>Number</li><li>Boolean</li><li>null</li><li>undefined</li><li>Symbol</li><li>BigInt</li></ul><p>Primitive values stack memory ma store hunxa.</p><h3>Important Point</h3><p>👉 Stack memory ma variable ko <strong>copy</strong> milxa.<br> Original value directly share hudaina.</p><pre>let myName = &quot;sachin&quot;;<br><br>let anotherName = myName;<br><br>anotherName = &quot;english&quot;;<br><br>console.log(myName);<br>console.log(anotherName);</pre><p>Output</p><p>sachin<br>english</p><h4>How It Works Internally</h4><p><strong>Step 1</strong></p><pre>let myName = &quot;sachin&quot;;</pre><p>Stack memory ma:</p><pre>| Variable | Value    |<br>| -------- | -------- |<br>| myName   | &quot;sachin&quot; |</pre><p><strong>Step 2</strong></p><pre>let anotherName = myName;</pre><p>anotherName le myName ko <strong>copy</strong> paauxa.</p><pre>| Variable    | Value    |<br>| ----------- | -------- |<br>| myName      | &quot;sachin&quot; |<br>| anotherName | &quot;sachin&quot; |</pre><p>Step 3</p><pre>anotherName = &quot;english&quot;;</pre><p>Now only anotherName change hunxa.<br> myName same nai rahanchha.</p><pre>| Variable    | Value     |<br>| ----------- | --------- |<br>| myName      | &quot;sachin&quot;  |<br>| anotherName | &quot;english&quot; |</pre><h3>Note</h3><p>✅ Stack memory fast hunxa<br>✅ Primitive values immutable nature ko hunxan<br>✅ Copy create hunxa</p><h3>2. Heap Memory (Non-Primitive)</h3><p>Non-primitive types:</p><ul><li>Object</li><li>Array</li><li>Function</li></ul><p>Yo sab Heap memory ma store hunxa.</p><h3>Important Point</h3><p>👉 Heap memory ma original value ko <strong>reference/address</strong> pass hunxa.<br> Copy mildaina.</p><p>Tesaile ek variable bata change gareko value arko variable ma pani reflect hunxa.</p><h3>Example</h3><pre>let userOne = {<br>  name: &quot;sachin&quot;,<br>  email: &quot;<a href="/service/mailto:sachin@gmail.com">sachin@gmail.com</a>&quot;<br>}</pre><pre>let userTow = userOne;</pre><pre>userTow.email = &quot;<a href="/service/mailto:sachinUpdate@gmail.com">sachinUpdate@gmail.com</a>&quot;;</pre><pre>console.log(`userOne email ${userOne.email}`);<br>console.log(`userTow email ${userTow.email}`);</pre><h3>Output</h3><pre>userOne email sachinUpdate@gmail.com<br>userTow email sachinUpdate@gmail.com</pre><h4>How It Works Internally</h4><p>Step 1</p><pre>let userOne = {<br>  name: &quot;sachin&quot;,<br>  email: &quot;sachin@gmail.com&quot;<br>}</pre><p>Object heap memory ma create hunxa.</p><p>Stack ma chai object ko address/reference save hunxa.</p><pre>Stack:<br>userOne -&gt; 0x001<br><br>Heap:<br>0x001 -&gt; {<br>  name: &quot;sachin&quot;,<br>  email: &quot;sachin@gmail.com&quot;<br>}</pre><p>Step 2</p><pre>let userTow = userOne;</pre><p>userTow le same reference paauxa.</p><pre>Stack:<br>userOne -&gt; 0x001<br>userTow -&gt; 0x001</pre><p>Duitai same object lai point garirako xa.</p><p>Step 3</p><pre>userTow.email = &quot;sachinUpdate@gmail.com&quot;;</pre><p>Heap ma vako original object nai update hunxa.</p><pre>Heap:<br>0x001 -&gt; {<br>  name: &quot;sachin&quot;,<br>  email: &quot;sachinUpdate@gmail.com&quot;<br>}</pre><p>Tesaile userOne.email pani update vayo.</p><h4>Stack vs Heap Difference</h4><pre>| Stack Memory        | Heap Memory          |<br>| ------------------- | -------------------- |<br>| Primitive values    | Non-primitive values |<br>| Copy milxa          | Reference milxa      |<br>| Fast access         | Relatively slower    |<br>| Fixed size          | Dynamic size         |<br>| Independent changes | Shared changes       |<br>| Stored directly     | Stored via reference |</pre><h4>Memory Life Cycle in JavaScript</h4><p>JavaScript memory management ko lifecycle mainly 3 step ma hunxa:</p><h4>1. Allocate Memory</h4><p>Variable/object create garda memory allocate hunxa.</p><pre>const name = &quot;Sachin&quot;;<br>const user = { age: 22 };</pre><h4>2. Use Memory</h4><p>Read/write/update operations.</p><pre>console.log(user.age);<br><br>user.age = 23;</pre><h4>3. Release Memory</h4><p>Jaba object/variable required hudaina taba garbage collector le clean garxa.</p><h4>Garbage Collection (GC)</h4><p>JavaScript automatically unused memory remove garxa.</p><p>Yo process lai:</p><h4>Garbage Collection</h4><p>vaninxa.</p><h4>Garbage Collector Kasari Kaam Garxa?</h4><p>Modern JavaScript engines use:</p><h4>Mark-and-Sweep Algorithm</h4><h4>Mark-and-Sweep Simple Explanation</h4><p>GC le global scope bata reachable objects mark garxa.</p><p>Reachable chain ma navako objects delete garxa.</p><pre>let user = {<br>  name: &quot;Sachin&quot;<br>};<br><br>user = null;</pre><h4>K vayo?</h4><ul><li>Object pahila reachable thiyo</li><li>user = null paxi reference remove vayo</li><li>Aba object unreachable vayo</li><li>Garbage collector le memory free garxa</li></ul><h4>Reference Concept</h4><p>Object le arko object access garna sakyo vane reference hunxa.</p><pre>const user = {<br>  address: {<br>    city: &quot;Kathmandu&quot;<br>  }<br>}</pre><p>Here:</p><ul><li>user references address</li><li>address object reachable xa</li></ul><h4>Circular Reference Problem</h4><pre>function test() {<br>  const x = {};<br>  const y = {};<br><br>  x.ref = y;<br>  y.ref = x;<br>}</pre><p>Old reference-counting GC ma yo memory leak hunthyo.</p><p>किन?</p><p>Because:</p><ul><li>x references y</li><li>y references x</li></ul><p>Duitai ko reference count 0 hudaina.</p><h4>Modern Engines Solution</h4><p>Modern JS engines use:</p><p>✅ Mark-and-Sweep<br> So circular reference pani clean hunxa if unreachable from global scope.</p><h4>WeakMap and WeakSet</h4><p>JavaScript ma special memory-friendly structures pani xa:</p><ul><li>WeakMap</li><li>WeakSet</li></ul><p>Yo structures le objects lai weakly hold garxa.</p><p>Meaning:</p><p>👉 object elsewhere use navaye garbage collect huna sakxa.</p><h4>WeakMap Example</h4><pre>const wm = new WeakMap();<br><br>let user = {<br>  name: &quot;Sachin&quot;<br>};<br><br>wm.set(user, &quot;Developer&quot;);<br><br>user = null;</pre><p>Now object garbage collect huna sakxa.</p><h4>WeakRef</h4><p>WeakRef le object garbage collect vayepani weak reference maintain garna dinxa.</p><pre>const weakRef = new WeakRef(obj);</pre><p>Mostly advanced optimization ma use hunxa.</p><h4>FinalizationRegistry</h4><p>Object garbage collect vayepaxi cleanup callback trigger garna use hunxa.</p><p>Advanced memory optimization ma useful.</p><h3>Important Interview Question 🔥</h3><h4>Primitive</h4><ul><li>Stored in stack</li><li>Copy milxa</li><li>Immutable</li></ul><h4>Non-Primitive</h4><ul><li>Stored in heap</li><li>Reference milxa</li><li>Mutable</li></ul><h4>Real Life Analogy</h4><h4>Stack</h4><p>Photocopy jasto.</p><p>Original document bata copy nikale jasto.<br> Copy ma change gare original change hudaina.</p><h4>Heap</h4><p>Google Docs shared link jasto.</p><p>Sabai same document ma connected hunxan.<br> Ek jana le change gare sabai ma reflect hunxa.</p><h3>Final Summary</h3><h3>Stack Memory</h3><p>✅ Primitive values<br>✅ Copy create hunxa<br>✅ Fast<br>✅ Independent changes</p><h3>Heap Memory</h3><p>✅ Objects/Arrays/Functions<br>✅ Reference share hunxa<br>✅ Original value change hunxa<br>✅ Dynamic memory allocation</p><h4>Short Note</h4><pre>Primitive -&gt; Stack -&gt; Copy<br>Non-Primitive -&gt; Heap -&gt; Reference</pre><h3>Conclusion</h3><p>JavaScript memory management internally dherai powerful xa.<br> Developer le manually memory free garnu pardaina because JavaScript engine le Garbage Collection automatically handle garxa.</p><p>But memory kasari work garxa bujhyo vane:</p><ul><li>better debugging</li><li>performance optimization</li><li>memory leak avoid</li><li>interview preparation</li></ul><p>dherai easy hunxa 🚀</p><h3>1. What is Stack Memory in JavaScript?</h3><p>Stack memory primitive data types store garna use hunxa.</p><p>Example:</p><ul><li>String</li><li>Number</li><li>Boolean</li><li>undefined</li><li>null</li></ul><p>Stack ma value directly store hunxa ra variable assign garda copy create hunxa.</p><pre>let a = 10;<br>let b = a;<br><br>b = 20;<br><br>console.log(a);<br>console.log(b);<br><br>Output:<br><br>10<br>20<br><br>b change garda a change hudaina because copy pass vako xa.</pre><h3>2. What is Heap Memory?</h3><p>Heap memory non-primitive data store garna use hunxa.</p><p>Example:</p><ul><li>Object</li><li>Array</li><li>Function</li></ul><p>Heap ma actual object store hunxa ra stack ma tesko reference/address store hunxa.</p><pre>const user1 = {<br>  name: &quot;Sachin&quot;<br>};<br><br>const user2 = user1;<br><br>user2.name = &quot;English&quot;;<br><br>console.log(user1.name);<br><br>Output:<br><br>English</pre><p>Because same object ko reference share vako xa.</p><h3>3. Difference Between Stack and Heap Memory?</h3><pre>| Stack               | Heap                 |<br>| ------------------- | -------------------- |<br>| Primitive values    | Non-primitive values |<br>| Copy milxa          | Reference milxa      |<br>| Faster              | Slower               |<br>| Fixed size          | Dynamic size         |<br>| Independent changes | Shared changes       |</pre><h3>4. Why Primitive Values are Immutable?</h3><p>Primitive values directly modify hudainan.<br> New value create hunxa.</p><pre>let name = &quot;Sachin&quot;;<br><br>name[0] = &quot;P&quot;;<br><br>console.log(name);<br><br>Output: Sachin</pre><p>String immutable ho.</p><h3>5. Why Objects are Mutable?</h3><p>Objects heap memory ma store hunxan.<br>Reference use hunxa.</p><p>Object properties dynamically modify garna milxa.</p><pre>const user = {<br>  name: &quot;Sachin&quot;<br>};<br><br>user.name = &quot;English&quot;;<br><br>console.log(user.name);<br><br>Output:English</pre><h3>6. Explain Pass By Value and Pass By Reference</h3><h3>Pass By Value</h3><p>Primitive values copy hunxa.</p><pre>let x = 10;<br>let y = x;<br><br>y = 20;</pre><p>x affect hudaina.</p><p><strong>Pass By Reference</strong></p><p>Objects ko reference share hunxa.</p><pre>const a = {<br>  name: &quot;Sachin&quot;<br>};<br><br>const b = a;</pre><p>Duitai same object lai point garxan.</p><h3>7. What will be the output?</h3><pre>const a = [];<br>const b = [];<br><br>console.log(a === b);</pre><p>Answer</p><pre>false</pre><p>Because objects/arrays compare by reference not value.</p><p>Both arrays different memory location ma xa.</p><h3>8. What will be the output?</h3><pre>const user1 = {<br>  name: &quot;Sachin&quot;<br>};<br><br>const user2 = user1;<br><br>user2.name = &quot;English&quot;;<br><br>console.log(user1.name);<br><br>Answer<br><br>English</pre><p>Because same heap reference share vako xa.</p><h3>9. What is Garbage Collection?</h3><p>Garbage collection JavaScript ko automatic memory cleanup process ho.</p><p>Unused memory automatically free garxa.</p><p>Developer le manually memory free garnu pardaina.</p><h3>10. What is Mark-and-Sweep Algorithm?</h3><h4>Answer</h4><p>Modern JavaScript engines mark-and-sweep algorithm use garxan.</p><h4>Process:</h4><ol><li>Reachable objects mark garxa</li><li>Unreachable objects remove garxa</li></ol><pre>let user = {<br>  name: &quot;Sachin&quot;<br>};<br><br>user = null;</pre><p>Now object unreachable vayo.<br> GC le cleanup garna sakxa.</p><h3>11. What is Memory Leak?</h3><h4>Answer</h4><p>Unused memory accidentally retain hunu lai memory leak vaninxa.</p><p>Example:</p><pre>let data = [];<br><br>function addData() {<br>  data.push(new Array(1000000).fill(&quot;🔥&quot;));<br>}</pre><p>Repeated call garda memory increase hunxa because data global scope ma still referenced xa.</p><h3>12. What is Shallow Copy?</h3><h3>Answer</h3><p>Shallow copy ma nested objects ko reference same hunxa.</p><pre>const user1 = {<br>  name: &quot;Sachin&quot;<br>};<br><br>const user2 = user1;</pre><p>Same reference share hunxa.</p><h3>13. What is Deep Copy?</h3><h4>Answer</h4><p>Deep copy ma completely new object create hunxa.</p><pre>const user1 = {<br>  name: &quot;Sachin&quot;<br>};<br><br>const user2 = {<br>  ...user1<br>};<br><br>user2.name = &quot;English&quot;;<br><br>console.log(user1.name);</pre><p>Output</p><pre>Sachin</pre><h3>14. What is WeakMap?</h3><h4>Answer</h4><p>WeakMap weakly referenced objects store garna use hunxa.</p><p>If object elsewhere referenced xaina vane garbage collect huna sakxa.</p><pre>const wm = new WeakMap();<br><br>let obj = {};<br><br>wm.set(obj, &quot;data&quot;);<br><br>obj = null;</pre><p>Now object eligible for GC.</p><h3>15. What is the difference between null and undefined in memory?</h3><h4>Answer</h4><h4>undefined</h4><p>Variable declared but value assign navako.</p><pre>let a;</pre><h4>null</h4><p>Intentional empty value.</p><pre>let user = null;</pre><h3>16. What happens internally when object is created?</h3><pre>const user = {<br>  name: &quot;Sachin&quot;<br>};</pre><p>Internally:</p><ul><li>Heap ma object create hunxa</li><li>Stack ma reference store hunxa</li></ul><pre>Stack:<br>user -&gt; 0x001<br><br>Heap:<br>0x001 -&gt; { name: &quot;Sachin&quot; }</pre><h3>17. What is Call Stack?</h3><h4>Answer</h4><p>Function execution manage garne mechanism ho.</p><p>Functions stack ma push/pop hunxan.</p><pre>function one() {<br>  two();<br>}<br><br>function two() {<br>  console.log(&quot;Hello&quot;);<br>}<br><br>one();</pre><p>Execution order:</p><pre>Global()<br>one()<br>two()</pre><h3>18. Why JavaScript is called Garbage Collected Language?</h3><h3>Answer</h3><p>✅ Stack faster hunxa.</p><p>Because:</p><ul><li>Fixed size</li><li>Sequential allocation</li><li>Easy access</li></ul><p>Heap dynamic hunxa so relatively slower.</p><h3>20. Important Interview One-Liner 🔥</h3><h3>Primitive</h3><pre>Primitive values are stored directly in stack memory and copied by value.</pre><h3>21. Tricky Interview Question 🔥</h3><pre>let a = {<br>  value: 10<br>};<br><br>let b = a;<br><br>b = {<br>  value: 20<br>};<br><br>console.log(a.value);</pre><h4>Answer</h4><pre>10</pre><p>Because:</p><p>b now points to completely new object.</p><p>Original object unchanged.</p><h3>22. Another Tricky Question 🔥</h3><pre>const arr1 = [1, 2];<br><br>const arr2 = arr1;<br><br>arr2.push(3);<br><br>console.log(arr1);</pre><p>Output</p><pre>[1,2,3]</pre><p>Same reference share vako xa.</p><h3>23. Why Functions are stored in Heap?</h3><h3>Answer</h3><p>Functions JavaScript ma special type ko object ho.</p><p>Tesaile heap memory ma allocate hunxa.</p><pre>function greet() {}<br><br>console.log(typeof greet);</pre><p>Output:</p><pre>function</pre><h4>Final Interview Summary 🚀</h4><pre>Primitive -&gt; Stack -&gt; Copy<br><br>Non-Primitive -&gt; Heap -&gt; Reference<br><br>Garbage Collector -&gt; Automatically cleans unused memory<br><br>Modern GC -&gt; Mark and Sweep</pre><h3>Pro Interview Tip 🔥</h3><p>Interviewer le mostly yo kura sodhna sakxa:</p><ul><li>Stack vs Heap</li><li>Shallow vs Deep Copy</li><li>Memory Leak</li><li>Garbage Collection</li><li>Pass by Value vs Reference</li><li>Call Stack</li><li>Closure memory behavior</li><li>Object comparison</li></ul><p>Yo sab clear vayo vane JavaScript fundamentals strong maninxa 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9680976c1828" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>