Why a=[7,9]; b=[7,9] Console.log(a==b)//false ? | Sololearn: Learn to code for FREE!
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 ?

16th Jun 2020, 4:03 PM
Kazi Alauddin
Kazi Alauddin - avatar
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.
19th Jun 2020, 11:20 AM
TolaTechy
TolaTechy - avatar