empy

[] is not identical to [] [duplicate]

你离开我真会死。 提交于 2019-12-02 05:43:58
问题 This question already has answers here : How to compare arrays in JavaScript? (55 answers) Closed 5 years ago . I was asked to write a function sortByFoo in Javascript that would react correctly to this test : // Does not crash on an empty array console.log(sortByFoo([]) === []); But I've tried something : [] === []; >> false Just so I can be sure, such a test would always fail, no matter the sortByFoo function, wouldn't it ? But I'd like to have an explanation on why this happens. Why [] isn

[] is not identical to [] [duplicate]

我是研究僧i 提交于 2019-12-02 02:35:39
This question already has an answer here: How to compare arrays in JavaScript? 54 answers I was asked to write a function sortByFoo in Javascript that would react correctly to this test : // Does not crash on an empty array console.log(sortByFoo([]) === []); But I've tried something : [] === []; >> false Just so I can be sure, such a test would always fail, no matter the sortByFoo function, wouldn't it ? But I'd like to have an explanation on why this happens. Why [] isn't identical/equal to [] ? Please forgive my approximate english, it is not my native language :p If you look at the