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
Great breakdown, the analogy explains it nicely 👌 Appreciate the mention and helping more people understand what’s really happening under the hood.💚
Thanks for tagging us and spreading the word! 🚀
They are distinct instances stored in different memory addresses. Btw i was talking about the houses and rooms not the syntax 😜
[] === [] is false because arrays are compared by reference, not by values — even empty arrays have different memory locations. For deep comparison, JSON.stringify(obj1) === JSON.stringify(obj2) can work in simple cases, but it depends on key order and data types, and complex data usually needs a proper deep comparison method.
=> Objects, arrays, functions → comparison by reference, never by value => Primitives (number, string, boolean) → comparison by value 0===0// true "abc"==="abc"// true [] === [] // false
Identical? Two different arrays are different arrays, doesn't matter that of the same type.
Your img has a syntax error
Because of reference
Due to by reference in memory assignment.
Bhai teri image generation me bhi kami h 😂. []==={]