New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Why a=[7,9]; b=[7,9] Console.log(a==b)//false ?
1 Answer
+ 3
JavaScript arrays and objects usually compare by reference. It'll only return true if both variables reference same object.
For example;
a=[7,9]
a=b
console.log(a===b) //true
In this case, both a and b are referencing same array.
Nonetheless, you can still compare two different arrays or objects by value if you iterate through them.