Is there a reason as to why these statements evaluate to true?
0 == [0];
1 == [1];
5 == [5];
5000 == [5000];
1000000 == [1000000];
So basically any number equals itself wrapped in an array? What’s the logic behind this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s because the non-strict equality operator coerces both its operands to strings in this case, and the string representation of an array is the elements it contains, delimited by commas:
Since the arrays in your question only contain one element, their string representation is the same as their element’s: