+ 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);
9 ответов
+ 2
ILLUMINATIE so works it in javascript. Javascript offers no possibility to compare of objects.
+ 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“
+ 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....
+ 1
👍👍thank you for explaining this,stay happy with play coding friends,once again thank you for all!😃😃
+ 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...)
+ 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.
+ 1
js does not directly compare directly to any object, it will ask for a reference !. here it is right, friends?
+ 1
Yes, ILLUMINATIE . Array is an object and here javascript up to now compares they references only and not properties of them.
0
No,it is confused me!