JavaScript Hacks: Arrays and Objects Compared by Reference

JavaScript Hacks - 😶🌫️ These two lines expose who actually understands JavaScript. ------------------ console.log([] == []); console.log({} == {}); ------------------ The output is false and false. This surprises people who think JavaScript compares values. → Arrays and objects live in memory, and JavaScript compares their memory addresses, not their contents. → Every new array or object gets a brand new reference, even if it looks identical. → [] and [] are two different memory locations, so the comparison fails immediately. → The same rule applies to objects, functions, and class instances. → JavaScript compares objects by reference, not by value. #javascript #frontend #hacks #interviewpreparation

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories