To check if an array is empty , we have many choices like if(array.length===0) or if(array=='')but I'm wondering whyif (array==[]) doesn't check if an array is empty or not. Any one has a clear explanation?
I was posting an answer that you said you find the answer :). Note that [] is new object with new reference and when you use == you are checking the reference of them not value of the objects
@AlirezaAhmadi With 2.2 million JavaScript questions on Stack Overflow, you can almost guarantee that a question like this one has a duplicate. Always search for one before answering.
@Ivar I think OP searched his question before asked. I always focus on the answer. But it seems you are right some OP does not search before asking his question
Double Equals ( == ) checks for value equality only. It inherently does type coercion. This means that before checking the values, it converts the types of the variables to match each other. and in the same way [] doesn't have any type and if(arr == []) doesn't work in javascript
[]is new object with new reference and when you use==you are checking the reference of them not value of the objects