JavaScript Interview Trap: Arrays and Objects as Reference Types

🧠 JavaScript Interview Trap – Do You Know the Output? Consider this: console.log([] == []); console.log([] === []); console.log({} == {}); console.log({} === {}); 👉 Output: All four will return false 💡 Why? In JavaScript, arrays and objects are reference types, not primitive values. Every time you create "[]" or "{}", JavaScript allocates a new memory reference. So when you compare them: - "[] === []" → different references → false - "{}" === "{}" → different references → false Even if they look identical, JavaScript compares references, not structure or content. ⚡ Key Takeaway: Same shape ≠ Same reference This is one of the most common JavaScript interview traps for frontend developers. #JavaScript #FrontendDevelopment #WebDevelopment #MERNStack #CodingInterview #JSConcepts

This concept definitely trips up more developers than we'd like to admit, especially when you're expecting those comparisons to just work intuitively.

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories