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

28th Sep 2024, 5:36 PM
LORD HOSSEIN
LORD HOSSEIN - avatar
2 odpowiedzi
+ 1
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.
28th Sep 2024, 5:44 PM
Jerry Hobby
Jerry Hobby - avatar
28th Sep 2024, 10:14 PM
Sharpneli
Sharpneli - avatar