0
Why this is false
Can someone explain why this is false?? let arr1 = [2, 4, 5, 'text']; let arr2 = [2, 4, 5, 'text']; console.log(arr1 == arr2); https://sololearn.com/compiler-playground/cgXvDUxkF870/?ref=app
4 ответов
+ 6
The code will output false because in JavaScript, arrays are compared by reference, not by value. Even though arr1 and arr2 contain the same elements, they are different objects in memory.
To compare the contents, you need to loop through them and compare the various elements and compare the length of each list.
+ 1
0
Jerry Hobby I thought that only happens in languages that don’t automatically detect variables, like Java, C#, and C++
0
Sharpneli Thanks, but I already know that