+ 1

Why given below code's output is false?

var a=[1,2,3,'hi']; var b=[1,2,3,'hi']; console.log(a == b);

17th Jul 2020, 6:38 PM
ILLUMINATIE
ILLUMINATIE - avatar
9 Answers
+ 2
ILLUMINATIE so works it in javascript. Javascript offers no possibility to compare of objects.
17th Jul 2020, 7:24 PM
JaScript
JaScript - avatar
+ 1
That are different objects. The objects are equal as follows. let objectA= {value: 50}; let objectB= objectA; let objectC= {value: 50}; console.log(objectA==objectB; // → true console.log(objectA== objectC); // → false“
17th Jul 2020, 7:09 PM
JaScript
JaScript - avatar
+ 1
A and b are not the same, because if you for example change a to [1,2,3,’hello’] then b would stay the same....
17th Jul 2020, 7:17 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
👍👍thank you for explaining this,stay happy with play coding friends,once again thank you for all!😃😃
17th Jul 2020, 7:23 PM
ILLUMINATIE
ILLUMINATIE - avatar
+ 1
ILLUMINATIE you are welcome! It was a honour to answer your question! happy coding (btw.: If you question is solved you could edit it and add solved tag...)
17th Jul 2020, 7:27 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
var a=[1,2,3,'hi']; var b=[1,2,3,'hi'] ; console.log(a == b); //false Because it compares refference for Arrays by == opearator. Look this: var a = [1,2,3,'hi']; var b=a, console.log(a == b) ; //true By b=a, now both points same address.
17th Jul 2020, 7:28 PM
Jayakrishna 🇼🇳
+ 1
js does not directly compare directly to any object, it will ask for a reference !. here it is right, friends?
17th Jul 2020, 7:48 PM
ILLUMINATIE
ILLUMINATIE - avatar
+ 1
Yes, ILLUMINATIE . Array is an object and here javascript up to now compares they references only and not properties of them.
18th Jul 2020, 7:39 AM
JaScript
JaScript - avatar
0
No,it is confused me!
17th Jul 2020, 7:13 PM
ILLUMINATIE
ILLUMINATIE - avatar