I’ve been working with #JavaScript 𝗳𝗼𝗿 𝘆𝗲𝗮𝗿𝘀 𝗮𝗻𝗱 𝗵𝗮𝘃𝗲 𝘀𝘂𝗰𝗰𝗲𝘀𝘀𝗳𝘂𝗹𝗹𝘆 𝗰𝗹𝗲𝗮𝗿𝗲𝗱 interviews by understanding how it works under the hood. If you’ve written basic JavaScript functions, worked with closures, or used async/await, you’re already halfway there. ➤ Here are 20 JavaScript questions you should prepare for to break into top product-based companies (PBCs): 𝟭. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗝𝘂𝘀𝘁-𝗜𝗻-𝗧𝗶𝗺𝗲 (𝗝𝗜𝗧) 𝗰𝗼𝗺𝗽𝗶𝗹𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗵𝗼𝘄 𝗱𝗼𝗲𝘀 𝗶𝘁 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗲 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲? → What are baseline vs optimizing compilers, and how does V8 use them? 𝟮. 𝗛𝗼𝘄 𝗱𝗼 𝗵𝗶𝗱𝗱𝗲𝗻 𝗰𝗹𝗮𝘀𝘀𝗲𝘀 𝗮𝗻𝗱 𝗶𝗻𝗹𝗶𝗻𝗲 𝗰𝗮𝗰𝗵𝗶𝗻𝗴 𝗶𝗺𝗽𝗮𝗰𝘁 𝗮𝗽𝗽 𝘀𝗽𝗲𝗲𝗱? → How can property access patterns affect engine optimizations? 𝟯. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝘁𝗵𝗲 𝗲𝘃𝗲𝗻𝘁 𝗹𝗼𝗼𝗽 𝗮𝗻𝗱 𝗵𝗼𝘄 𝗱𝗼 𝗺𝗶𝗰𝗿𝗼𝘁𝗮𝘀𝗸𝘀 𝘃𝘀 𝗺𝗮𝗰𝗿𝗼𝘁𝗮𝘀𝗸𝘀 𝗲𝘅𝗲𝗰𝘂𝘁𝗲? → Why does Promise.then() run before setTimeout()? 𝟰. 𝗛𝗼𝘄 𝗱𝗼 𝗰𝗹𝗼𝘀𝘂𝗿𝗲𝘀 𝘄𝗼𝗿𝗸 𝗮𝗻𝗱 𝗵𝗼𝘄 𝗰𝗮𝗻 𝘁𝗵𝗲𝘆 𝗹𝗲𝗮𝗸 𝗺𝗲𝗺𝗼𝗿𝘆? → What real-world issues have you seen or debugged related to retained scope? 𝟱. 𝗪𝗵𝗮𝘁 𝗶𝘀 𝘁𝗵𝗲 𝗧𝗲𝗺𝗽𝗼𝗿𝗮𝗹 𝗗𝗲𝗮𝗱 𝗭𝗼𝗻𝗲 (𝗧𝗗𝗭)? → Why does let behave differently than var during hoisting? 𝟲. 𝗛𝗼𝘄 𝗱𝗼𝗲𝘀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗺𝗮𝗻𝗮𝗴𝗲 𝗺𝗲𝗺𝗼𝗿𝘆 𝗶𝗻 𝗵𝗲𝗮𝗽 𝘃𝘀 𝘀𝘁𝗮𝗰𝗸? → How do objects, functions, and primitives get allocated and cleaned up? 𝟳. 𝗛𝗼𝘄 𝗱𝗼 𝗪𝗲𝗮𝗸𝗠𝗮𝗽 𝗮𝗻𝗱 𝗪𝗲𝗮𝗸𝗦𝗲𝘁 𝗵𝗲𝗹𝗽 𝗮𝘃𝗼𝗶𝗱 𝗺𝗲𝗺𝗼𝗿𝘆 𝗹𝗲𝗮𝗸𝘀? → When would you use them over regular Maps or Sets? 𝟴. 𝗛𝗼𝘄 𝗱𝗼𝗲𝘀 𝘁𝗵𝗲 𝘁𝗵𝗶𝘀 𝗸𝗲𝘆𝘄𝗼𝗿𝗱 𝗯𝗲𝗵𝗮𝘃𝗲 𝗶𝗻 𝗮𝗿𝗿𝗼𝘄 𝘃𝘀 𝗿𝗲𝗴𝘂𝗹𝗮𝗿 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀? → What issues does this cause in event handlers or class methods? 𝟵. 𝗛𝗼𝘄 𝘄𝗼𝘂𝗹𝗱 𝘆𝗼𝘂 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁 𝗮 𝗱𝗲𝗯𝗼𝘂𝗻𝗰𝗲 𝗼𝗿 𝘁𝗵𝗿𝗼𝘁𝘁𝗹𝗲 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻 𝗳𝗿𝗼𝗺 𝘀𝗰𝗿𝗮𝘁𝗰𝗵? → Where have you applied this in a real-world project? 𝟭𝟬. 𝗪𝗵𝗮𝘁 𝗮𝗿𝗲 𝗧𝘆𝗽𝗲𝗱 𝗔𝗿𝗿𝗮𝘆𝘀 𝗮𝗻𝗱 𝗵𝗼𝘄 𝗱𝗼 𝘁𝗵𝗲𝘆 𝗲𝗻𝗵𝗮𝗻𝗰𝗲 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲? → How are they different from normal arrays, and when would you use them? If you can confidently explain how JS works, not just use it, you’ll stand out in interviews and code reviews. 𝗜 𝗵𝗮𝘃𝗲 𝗽𝗿𝗲𝗽𝗮𝗿𝗲𝗱 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗣𝗿𝗲𝗽𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝗚𝘂𝗶𝗱𝗲 𝗳𝗼𝗿 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗘𝗻𝗴𝗶𝗻𝗻𝗲𝗿𝘀. covering JavaScript, React, Next.js, System Design, and more. 𝗚𝗲𝘁 𝘁𝗵𝗲 𝗚𝘂𝗶𝗱𝗲 𝗵𝗲𝗿𝗲 - https://lnkd.in/d2w4VmVT 💙- If you've read so far, do LIKE and RESHARE the post
Utpal Mahata’s Post
More Relevant Posts
-
What is result of [] === [] in javascript ? If you can’t answer this, your React apps are likely re-rendering way more than they should. In JavaScript and TypeScript, the answer is false. But why? Understanding this is the key to mastering performance and avoiding those "phantom" bugs in useEffect. 🏠 The "Two Houses" Analogy Imagine two houses. They have the exact same floor plan, the same paint color, and the same furniture. * Are they the same style? Yes. * Are they the same address? No. In JavaScript, Objects, Arrays, and Functions are Reference Types. When you create [], you aren't just creating a value; you are allocating a specific spot in memory (an address). * The first [] lives at Address A. * The second [] lives at Address B. When you use ===, JavaScript doesn't look at the "furniture" inside the array. It asks: "Are these two pointing to the exact same address?" Since Address A is not Address B, the result is false. ⚠️ Why this is a "React Killer" React uses Shallow Comparison to decide if it should re-render or trigger an effect. If you define an object or array inside your component body like this: useEffect(() => { // This runs on EVERY single render! console.log("Data fetched"); }, [ { id: 1 } ]); // ❌ New object = New reference every time Even though the ID is always 1, React sees a new address every time the component functions runs. It thinks the data has changed, so it triggers the effect again. And again. And again. ✅ How to fix it To keep your app fast, you need to preserve the Reference: * Move it outside: If the data is static, define it outside the component. * useMemo: Wrap objects/arrays in useMemo to keep the same memory address between renders. * useCallback: Use this for functions to prevent them from being "re-created" on every render. The Golden Rule: In React, it's not just about what the data is, it's about where it lives in memory. Have you ever spent hours debugging a useEffect loop only to realize it was a reference issue? Let’s talk about it in the comments! 👇 #JavaScript #TypeScript #ReactJS #WebDevelopment #FrontendEngineering #CodingTips #PerformanceOptimization 🇩🇪 Zusammenfassung Dieser Post erklärt, warum der Vergleich [] === [] in JavaScript false ergibt, da Objekte und Arrays nach ihrer Speicheradresse (Referenz) und nicht nach ihrem Inhalt verglichen werden. In React führt dies oft zu unnötigen Re-Renders, weshalb man Techniken wie useMemo oder useCallback nutzen muss, um die Referenz stabil zu halten.
To view or add a comment, sign in
-
-
What is result of [] === [] in javascript ? If you can’t answer this, your React apps are likely re-rendering way more than they should. In JavaScript and TypeScript, the answer is false. But why? Understanding this is the key to mastering performance and avoiding those "phantom" bugs in useEffect. 🏠 The "Two Houses" Analogy Imagine two houses. They have the exact same floor plan, the same paint color, and the same furniture. * Are they the same style? Yes. * Are they the same address? No. In JavaScript, Objects, Arrays, and Functions are Reference Types. When you create [], you aren't just creating a value; you are allocating a specific spot in memory (an address). * The first [] lives at Address A. * The second [] lives at Address B. When you use ===, JavaScript doesn't look at the "furniture" inside the array. It asks: "Are these two pointing to the exact same address?" Since Address A is not Address B, the result is false. ⚠️ Why this is a "React Killer" React uses Shallow Comparison to decide if it should re-render or trigger an effect. If you define an object or array inside your component body like this: useEffect(() => { // This runs on EVERY single render! console.log("Data fetched"); }, [ { id: 1 } ]); // ❌ New object = New reference every time Even though the ID is always 1, React sees a new address every time the component functions runs. It thinks the data has changed, so it triggers the effect again. And again. And again. ✅ How to fix it To keep your app fast, you need to preserve the Reference: * Move it outside: If the data is static, define it outside the component. * useMemo: Wrap objects/arrays in useMemo to keep the same memory address between renders. * useCallback: Use this for functions to prevent them from being "re-created" on every render. The Golden Rule: In React, it's not just about what the data is, it's about where it lives in memory. Have you ever spent hours debugging a useEffect loop only to realize it was a reference issue? Let’s talk about it in the comments! 👇 w3schools.com JavaScript Mastery #JavaScript #TypeScript #ReactJS #WebDevelopment #FrontendEngineering #CodingTips #PerformanceOptimization
To view or add a comment, sign in
-
-
What is result of [] === [] in javascript ? If you can’t answer this, your React apps are likely re-rendering way more than they should. In JavaScript and TypeScript, the answer is false. But why? Understanding this is the key to mastering performance and avoiding those "phantom" bugs in useEffect. 🏠 The "Two Houses" Analogy Imagine two houses. They have the exact same floor plan, the same paint color, and the same furniture. * Are they the same style? Yes. * Are they the same address? No. In JavaScript, Objects, Arrays, and Functions are Reference Types. When you create [], you aren't just creating a value; you are allocating a specific spot in memory (an address). * The first [] lives at Address A. * The second [] lives at Address B. When you use ===, JavaScript doesn't look at the "furniture" inside the array. It asks: "Are these two pointing to the exact same address?" Since Address A is not Address B, the result is false. ⚠️ Why this is a "React Killer" React uses Shallow Comparison to decide if it should re-render or trigger an effect. If you define an object or array inside your component body like this: useEffect(() => { // This runs on EVERY single render! console.log("Data fetched"); }, [ { id: 1 } ]); // ❌ New object = New reference every time Even though the ID is always 1, React sees a new address every time the component functions runs. It thinks the data has changed, so it triggers the effect again. And again. And again. ✅ How to fix it To keep your app fast, you need to preserve the Reference: * Move it outside: If the data is static, define it outside the component. * useMemo: Wrap objects/arrays in useMemo to keep the same memory address between renders. * useCallback: Use this for functions to prevent them from being "re-created" on every render. The Golden Rule: In React, it's not just about what the data is, it's about where it lives in memory. Have you ever spent hours debugging a useEffect loop only to realize it was a reference issue? Let’s talk about it in the comments! 👇 w3schools.com JavaScript Mastery #JavaScript #TypeScript #ReactJS #WebDevelopment #FrontendEngineering #CodingTips #PerformanceOptimization
To view or add a comment, sign in
-
-
🤔 Preparing for your next JavaScript interview? Today, we're tackling one of the most crucial and misunderstood concepts in JavaScript: The Event Loop. JavaScript is single-threaded, meaning it has only one "Call Stack" and can only do one thing at a time. So, how does it handle time-consuming operations like API calls (fetch) or timers (setTimeout) without freezing the entire browser? The answer is that the JavaScript engine doesn't work alone. It gets help from the browser environment and a manager called the Event Loop. Here’s the complete system in a nutshell: 1. The Call Stack: This is where your JavaScript code is executed, one line at a time. 2. Web APIs: These are features provided by the browser (not the JS engine). When your code calls a slow operation like setTimeout, the JS engine hands it off to the Web API to handle in the background. The engine then immediately moves on to the next line of code, keeping the Call Stack free. 3.The Callback Queue (or Task Queue): Once the Web API finishes its job (the timer completes, the data arrives), it doesn't interrupt your code. Instead, it places the function you provided (the "callback") into this waiting line. This brings us to the final, critical piece. How does the function get from the waiting line back into the main code to be run? ✅ Enter the Event Loop: The Event Loop is a simple, constantly running process with one golden rule: "If the Call Stack is empty, take the first item from the Callback Queue and push it onto the Call Stack to be executed." ``` console.log('First'); setTimeout(() => { console.log('Second'); }, 0); console.log('Third'); // Output: First, Third, Second ``` Why this order? 1. `console.log('First')` goes to the Call Stack and runs. 2. `setTimeout` is handed to a Web API. JavaScript immediately continues. 3. `console.log('Third')` goes to the Call Stack and runs. 4. The `Call Stack` is now empty. 5. In the background, the timer finishes instantly (0ms) and places its callback `() => console.log('Second')` into the Callback Queue. 6. The Event Loop sees the Call Stack is empty, takes the callback from the queue, and pushes it onto the stack to run. This system is what makes JavaScript "non-blocking." The Event Loop ensures that slow tasks wait their turn without ever freezing the user interface. #javascript #eventloop #asynchronousjavascript #webdevelopment #frontenddevelopment #backenddevelopment #nodejs #v8engine #callstack #microtasks
To view or add a comment, sign in
-
-
Tell me the different types of functions in JavaScript ! That was the question my interviewer asked and honestly, it sounded simple at first. Most of us immediately think: 👉 Normal functions 👉 Arrow functions But I knew this question was not about syntax… it was about how deeply I understand JavaScript as a language. So instead of stopping at definitions, I turned it into a conversation about how functions shape JavaScript architecture. I started simple. 👉 Regular (Named) Functions The classic `function greet() {}`. Great for reusability, hoisting, and clear stack traces. 👉 Function Expressions `const greet = function() {}` I explained how these give us more control and are often used in callbacks and closures. Then I leveled up. 👉 Arrow Functions `() => {}` I didn’t just say “shorter syntax.” I explained lexical `this`, why it matters in React, event handlers, and async logic. That’s when the discussion got interesting. 👉 Higher-Order Functions Functions that take other functions as arguments or return them. I connected this to real code: `map`, `filter`, `reduce`, middleware, and even custom hooks in React. Now we were talking about functional programming patterns, not just functions. 👉 Callback Functions Instead of defining it plainly, I explained how callbacks evolved from ➡️ synchronous callbacks ➡️ async callbacks ➡️ promises ➡️ async/await Showing how JavaScript handles asynchronous behavior through functions. Then I added depth. 👉 Pure Functions Functions with no side effects and predictable output. I tied this to state management, reducers, and performance optimization. 👉 IIFE (Immediately Invoked Function Expressions) I mentioned how they were used earlier for scope isolation before ES6 modules. 👉 Currying Functions Functions returning functions: `add(2)(3)` I explained how currying helps in partial application and reusable logic, especially in utility libraries. 👉 Unary Functions Functions that accept only one argument. I connected this to how methods like `map` can behave unexpectedly when extra parameters are passed — a subtle but impressive detail. If you're preparing for interviews, don’t just memorize definitions. For more insightful content checkout below: 🟦 𝑳𝒊𝒏𝒌𝒆𝒅𝑰𝒏 - https://lnkd.in/dwi3tV83 ⬛ 𝑮𝒊𝒕𝑯𝒖𝒃 - https://lnkd.in/dkW958Tj 🟥 𝒀𝒐𝒖𝑻𝒖𝒃𝒆 - https://lnkd.in/dDig2j75 or Priya Frontend Vlogz 🔷 𝐓𝐰𝐢𝐭𝐭𝐞𝐫 - https://lnkd.in/dyfEuJNt #frontend #javascript #react #reactjs #html #css #typescript #es6 #interviewquestions #interview #interviewpreparation
To view or add a comment, sign in
-
-
In 2 minutes, understand why these JS concepts are important. 𝟭. 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 & 𝗖𝗮𝗹𝗹 𝗦𝘁𝗮𝗰𝗸 - Understanding how JavaScript manages function calls helps debug and optimize your code execution. 𝟮. 𝗛𝗼𝗶𝘀𝘁𝗶𝗻𝗴 - Helps avoid bugs by knowing when variables and functions are available during runtime. 𝟯. 𝗜𝗜𝗙𝗘 (𝗜𝗺𝗺𝗲𝗱𝗶𝗮𝘁𝗲𝗹𝘆 𝗜𝗻𝘃𝗼𝗸𝗲𝗱 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻) - Useful for creating isolated scopes and preventing global variable conflicts. 𝟰. 𝗘𝘃𝗲𝗻𝘁 𝗟𝗼𝗼𝗽 & 𝗠𝗶𝗰𝗿𝗼𝘁𝗮𝘀𝗸𝘀 𝗤𝘂𝗲𝘂𝗲 - Crucial for understanding how asynchronous operations are handled in JavaScript. 𝟱. 𝗗𝗲𝗯𝗼𝘂𝗻𝗰𝗶𝗻𝗴 & 𝗧𝗵𝗿𝗼𝘁𝘁𝗹𝗶𝗻𝗴 - Improves performance by controlling the frequency of event function calls, especially for user inputs. 𝟲. 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗮𝗹 𝗜𝗻𝗵𝗲𝗿𝗶𝘁𝗮𝗻𝗰𝗲 - Key to understanding how objects share properties and methods, making JavaScript more powerful and flexible. 𝟳. 𝗗𝗲𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗗𝗲𝗳𝗮𝘂𝗹𝘁 𝗩𝗮𝗹𝘂𝗲𝘀 - Simplifies extracting data from objects and arrays, making your code cleaner and easier to read. 𝟴. 𝗧𝘆𝗽𝗲𝗱 𝗔𝗿𝗿𝗮𝘆𝘀 - Essential for handling binary data efficiently, such as working with large files or images in JavaScript. 𝟵. 𝗠𝗲𝗺𝗼𝗶𝘇𝗮𝘁𝗶𝗼𝗻 - Optimizes performance by saving the results of expensive function calls to prevent redundant calculations. 𝟭𝟬. 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗼𝗿𝘀 & 𝗜𝘁𝗲𝗿𝗮𝘁𝗼𝗿𝘀 - Helps manage complex or large datasets by pausing and resuming functions, improving performance 𝟭𝟭. 𝗖𝘂𝗿𝗿𝘆𝗶𝗻𝗴 & 𝗣𝗮𝗿𝘁𝗶𝗮𝗹 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 - Improves code reusability by breaking down functions into smaller, reusable units. 𝟭𝟮. 𝗠𝗲𝗺𝗼𝗿𝘆 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 & 𝗚𝗮𝗿𝗯𝗮𝗴𝗲 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 - Important for optimizing app performance and avoiding memory leaks by understanding how unused objects are cleaned up. 𝟭𝟯. 𝗠𝗼𝗱𝘂𝗹𝗲 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀 - Helps organize and maintain code in separate, reusable modules, making it easier to manage large codebases. 𝟭𝟰. 𝗦𝗵𝗮𝗱𝗼𝘄 𝗗𝗢𝗠 - Encapsulates the structure and behavior of components, promoting reusable and isolated components. 𝟭𝟱. 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 - Promotes cleaner, more maintainable code by using pure functions, immutability, and first-class functions. 𝟭𝟲. 𝗣𝗿𝗼𝘅𝘆 - Allows you to intercept and modify object behavior, offering dynamic control over object properties. 𝗜 𝗵𝗮𝘃𝗲 𝗽𝗿𝗲𝗽𝗮𝗿𝗲𝗱 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗣𝗿𝗲𝗽𝗮𝗿𝗮𝘁𝗶𝗼𝗻 𝗚𝘂𝗶𝗱𝗲 𝗳𝗼𝗿 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗘𝗻𝗴𝗶𝗻𝗻𝗲𝗿𝘀. covering JavaScript, React, Next.js, System Design, and more. 𝗚𝗲𝘁 𝘁𝗵𝗲 𝗚𝘂𝗶𝗱𝗲 𝗵𝗲𝗿𝗲 - https://lnkd.in/d2w4VmVT 💙- If you've read so far, do LIKE and RESHARE the post
To view or add a comment, sign in
-
𝗥𝗲𝗮𝗰𝘁.𝗷𝘀 𝗣𝗮𝗿𝘁 𝟮 (𝟮𝟬𝟮𝟲): 𝗝𝗦𝗫 𝗮𝗻𝗱 𝗣𝗿𝗼𝗽𝘀 𝘃𝘀 𝗦𝘁𝗮𝘁𝗲 𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲 🔥 𝗛𝗶 𝗲𝘃𝗲𝗿𝘆𝗼𝗻𝗲! 👋 In my last post, we discussed why React continues to dominate the frontend ecosystem in 2026. Today, let’s dive into two foundational concepts that every React developer must understand deeply: ✅ JSX (what it is + why it exists) ✅ Props vs State (data flow + behavior + re-render rules) 1) 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗝𝗦𝗫? 🤔 JSX stands for: 𝗝𝗦𝗫 = 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 + 𝗫𝗠𝗟 It allows us to write UI directly inside JavaScript, in a way that looks like HTML. It’s syntax that gets compiled into JavaScript behind the scenes. ✅ Why JSX exists (in simple terms) JSX makes React code: • More readable • Easier to maintain • Faster to build UIs • Better supported by IDEs + TypeScript 👉 𝗞𝗲𝘆 𝗿𝘂𝗹𝗲 𝘁𝗼 𝗿𝗲𝗺𝗲𝗺𝗯𝗲𝗿: 𝗔𝗻𝘆𝘁𝗵𝗶𝗻𝗴 𝗶𝗻𝘀𝗶𝗱𝗲 { } 𝗶𝘀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁. 𝗝𝗦𝗫 𝗿𝘂𝗹𝗲𝘀 𝗲𝘃𝗲𝗿𝘆 𝗯𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝗺𝘂𝘀𝘁 𝗸𝗻𝗼𝘄 • Return one parent element • Use className instead of class • Close all tags properly • Event handlers use camelCase (onClick, onChange) 2) 𝗣𝗿𝗼𝗽𝘀 𝘃𝘀 𝗦𝘁𝗮𝘁𝗲 ⚡ This is where most React confusion begins, and once you understand it, React becomes easy. ✅ Props (Parent → Child) 𝗣𝗿𝗼𝗽𝘀 𝗮𝗿𝗲 𝘃𝗮𝗹𝘂𝗲𝘀 𝗽𝗮𝘀𝘀𝗲𝗱 𝗳𝗿𝗼𝗺 𝗮 𝗽𝗮𝗿𝗲𝗻𝘁 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝘁𝗼 𝗮 𝗰𝗵𝗶𝗹𝗱 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁. Props are: • Read-only (child can’t modify them) • Unidirectional (flow only downward) • Like function arguments 𝗪𝗵𝗮𝘁 𝗵𝗮𝗽𝗽𝗲𝗻𝘀 𝘄𝗵𝗲𝗻 𝘁𝗵𝗲 𝗽𝗮𝗿𝗲𝗻𝘁 𝗿𝗲-𝗿𝗲𝗻𝗱𝗲𝗿𝘀? When the parent state changes: 1. Parent re-renders 2. New props are passed 3. Child re-renders with fresh props 4. That’s React’s default behavior. ✅ State (Component’s internal memory) 𝗦𝘁𝗮𝘁𝗲 𝗶𝘀 𝗶𝗻𝘁𝗲𝗿𝗻𝗮𝗹 𝗱𝗮𝘁𝗮 𝘀𝘁𝗼𝗿𝗲𝗱 𝗶𝗻𝘀𝗶𝗱𝗲 𝗮 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁. State is: • Mutable (changes over time) • Local to the component • Triggers re-render when updated 🔥 Important: State survives re-renders. If React re-renders a component, the state does NOT reset. 𝗕𝘂𝘁... ❌ State does NOT survive page refresh Refreshing the page restarts the entire React app: ❌ All state is lost ✅ Components start fresh ✅ Props are re-initialized If you want the state to persist across refresh, you need: • localStorage • sessionStorage • database • cookies • URL params 🎯 The easiest way to remember • 𝗣𝗿𝗼𝗽𝘀 = 𝗲𝘅𝘁𝗲𝗿𝗻𝗮𝗹 𝗱𝗮𝘁𝗮 (𝗽𝗮𝘀𝘀𝗲𝗱 𝗶𝗻) • 𝗦𝘁𝗮𝘁𝗲 = 𝗶𝗻𝘁𝗲𝗿𝗻𝗮𝗹 𝗱𝗮𝘁𝗮 (𝗺𝗮𝗻𝗮𝗴𝗲𝗱 𝗶𝗻𝘀𝗶𝗱𝗲) Next post: 𝚁̲𝚎̲𝚊̲𝚌̲𝚝̲ ̲𝙷̲𝚘̲𝚘̲𝚔̲𝚜̲ ̲𝙳̲𝚎̲𝚎̲𝚙̲ ̲𝙳̲𝚒̲𝚟̲𝚎̲ ̲(̲𝚞̲𝚜̲𝚎̲𝚂̲𝚝̲𝚊̲𝚝̲𝚎̲,̲ ̲𝚞̲𝚜̲𝚎̲𝙴̲𝚏̲𝚏̲𝚎̲𝚌̲𝚝̲,̲ ̲𝚞̲𝚜̲𝚎̲𝚁̲𝚎̲𝚏̲)̲ ̲+̲ ̲𝚆̲𝚑̲𝚎̲𝚗̲ ̲𝚝̲𝚘̲ ̲𝚞̲𝚜̲𝚎̲ ̲𝚎̲𝚊̲𝚌̲𝚑̲🚀̲ ̲ If you found this helpful, drop a 👍 or comment “Part 3,” and I’ll share the next one. #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #React2026 #LearnReact #StateManagement
To view or add a comment, sign in
-
-
90% of candidates fail JavaScript interviews because they ignore these questions. 1. Explain the JavaScript Execution Context and how it is created. 2. What happens during the Creation Phase and Execution Phase? 3. How does the JavaScript Event Loop work internally? 4. Explain the difference between Microtask Queue and Callback Queue with execution order. 5. How does Memory Management and Garbage Collection work in JavaScript? 6. What is Temporal Dead Zone (TDZ)? 7. How does Prototype Chain lookup work internally? 8. What is Object.create() and how is it different from class-based inheritance? 9. How does the "this" keyword behave in different execution contexts? 10. Explain Function Borrowing in JavaScript. 11. What is Currying and how is it implemented? 12. What is Partial Application? 13. Explain Closures with real-world performance use cases. 14. What is Module Pattern and why is it used? 15. What is the difference between ES Modules and CommonJS? 16. How does Tree Shaking work in JavaScript bundlers? 17. What are Generators and Iterators in JavaScript? 18. What is Symbol and why was it introduced? 19. What are WeakMap and WeakSet? When should you use them? 20. Explain Proxy and Reflect APIs. 21. What is Event Bubbling and Event Capturing? 22. How does Event Delegation improve performance? 23. What are Web Workers and when should they be used? 24. What is the difference between Debounce, Throttle, and requestAnimationFrame optimization? 25. What is the difference between async/await error handling and Promise chaining? 26. What is Race Condition in JavaScript and how can it be handled? 27. What are Service Workers and how do they enable PWA features? 28. How does Virtual DOM work and how is it different from Real DOM? 29. What is Hydration in modern frontend frameworks? 30. What are Memory Leaks in JavaScript applications and how can you detect and fix them? 💡 𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲𝘀 𝗧𝗵𝗮𝘁 𝗜𝗺𝗽𝗿𝗲𝘀𝘀 𝗥𝗲𝗰𝗿𝘂𝗶𝘁𝗲𝗿𝘀 • Shadow DOM + Virtual DOM basics • Pure Functions vs Side Effects • Higher-Order Functions • Arrows functions vs normal functions (implicit binding!) • Event Delegation • Memory leaks in JS 📌 𝗕𝗲𝘀𝘁 𝗙𝗿𝗲𝗲 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 • MDN JavaScript Docs → https://lnkd.in/dSXqwNRi • JS Info (goldmine) → https://javascript.info/ • FreeCodeCamp JS Course → https://lnkd.in/dewQ8pg9 𝗜'𝘃𝗲 𝗰𝗿𝗲𝗮𝘁𝗲𝗱 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲 𝗠𝗘𝗥𝗡 𝗦𝘁𝗮𝗰𝗸 𝗚𝘂𝗶𝗱𝗲. (I've covered all these inside the Mern Stack Guide.) 𝗚𝗲𝘁 𝘁𝗵𝗲 𝗚𝘂𝗶𝗱𝗲 𝗵𝗲𝗿𝗲 - https://lnkd.in/dauSXK5R 📣 If you're preparing for internships or fresher roles, mastering these is non-negotiable. Your Confidence in interviews depends on how deeply you understand these concepts, not how many projects you have built. 𝗙𝗼𝗹𝗹𝗼𝘄 𝗔𝘀𝗵𝗶𝘀𝗵 𝗠𝗶𝘀𝗮𝗹 𝗖𝗼𝗱𝗲𝘀 𝗼𝗻 𝗜𝗚: https://lnkd.in/dJqGy5_g Follow Ashish Misal for more tech insights. Repost this post for your network ♻️ #JavaScript #mern #react #node #mongo #frontend #webDev
To view or add a comment, sign in
-
Day 28/50 – JavaScript Interview Question? Question: What is destructuring in JavaScript? Simple Answer: Destructuring is a syntax that unpacks values from arrays or properties from objects into distinct variables. It provides a concise way to extract multiple values in a single statement. 🧠 Why it matters in real projects: Destructuring makes code cleaner and more readable, especially with React props, API responses, and function parameters. It's ubiquitous in modern JavaScript and reduces boilerplate code significantly. 💡 One common mistake: Trying to destructure null or undefined, which throws an error. Always provide default values or check for existence when destructuring data from APIs or external sources. 📌 Bonus: // Array destructuring const [first, second, ...rest] = [1, 2, 3, 4, 5]; console.log(first); // 1 console.log(second); // 2 console.log(rest); // [3, 4, 5] // Object destructuring const user = { name: 'Alice', age: 30, city: 'NYC' }; const { name, age } = user; console.log(name); // "Alice" // Renaming variables const { name: userName, age: userAge } = user; // Default values (prevents undefined) const { country = 'USA' } = user; console.log(country); // "USA" // Nested destructuring const data = { user: { profile: { email: 'a@b.com' } } }; const { user: { profile: { email } } } = data; // React props destructuring function UserCard({ name, age, onDelete }) { return <div>{name}, {age}</div>; } // Function parameters function displayUser({ name, age = 18 }) { console.log(`${name} is ${age}`); } // Common mistake - destructuring undefined const { x } = null; // ✗ TypeError! const { x } = null || {}; // ✓ Safe with fallback #JavaScript #WebDevelopment #Frontend #LearnInPublic #InterviewQuestions #Programming #TechInterviews #ES6 #Destructuring #WebDev #InterviewPrep
To view or add a comment, sign in
-
# 🚀 JavaScript Closures: The Magic Every Developer Should Understand Today I want to share one of the most powerful, yet often misunderstood concepts in JavaScript — **closures**. ## What is a Closure? A closure is a function that "remembers" variables from its outer scope, even after the outer function has finished executing. Sounds abstract? Let me break it down with a practical example. ## Real-World Use Case: Creating a Counter Imagine you need to create independent counters, each with its own state. This is where closures shine: ```javascript // Factory function to create a counter function createCounter() { let count = 0; // Private variable! return { increment: function() { count++; return count; }, decrement: function() { count--; return count; }, getValue: function() { return count; } }; } // Usage: const counter1 = createCounter(); const counter2 = createCounter(); console.log(counter1.increment()); // 1 console.log(counter1.increment()); // 2 console.log(counter2.increment()); // 1 ← Independent! ``` ## Why Does This Work? When we call `createCounter()`, a new scope is created with the variable `count`. The inner functions (`increment`, `decrement`, `getValue`) "close over" this variable, maintaining access to it even after `createCounter()` has finished executing. **Key insight:** Each call to `createCounter()` creates its OWN separate scope. That's why `counter1` and `counter2` are completely independent! ## Where Is This Used in Real Projects? ✅ **Data encapsulation** — private variables without classes ✅ **Factory functions** — creating objects with state ✅ **Event handlers** — preserving context for event callbacks ✅ **Memoization** — caching function results ✅ **Middleware** in Express.js and other frameworks ## Common Pitfall ```javascript // ❌ Classic loop mistake for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } // Output: 3, 3, 3 // ✅ Correct solution with closure for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } // Output: 0, 1, 2 ``` ## Performance Considerations Keep in mind: closures consume memory because they maintain references to variables. In most cases this isn't an issue, but in performance-critical code it's worth considering. ## Conclusion Closures aren't just a JavaScript quirk — they're a fundamental pattern that makes the language so expressive. Understanding closures opens the door to writing more elegant and functional code. --- 💡 Do you use closures frequently in your projects? Share your favorite use cases in the comments! #JavaScript #WebDevelopment #Programming #Coding #SoftwareEngineering #FrontendDevelopment #LearnToCode #Tech
To view or add a comment, sign in
-
Explore related topics
- Questions to Ask Interviewers
- Advanced React Interview Questions for Developers
- Backend Developer Interview Questions for IT Companies
- Best Questions to Ask at End of Interview
- Sharp Questions to Ask in Interviews
- How to Answer Common Interview Questions
- Interview Questions for Fast-Paced Workplaces
- Questions to Ask in an In-Person Interview
- Key Questions to Ask Potential Employers
- Common Behavioral Interview Questions To Prepare For
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
interested