var c = false;
if(c=[] && c.length==0)alert('hi');
hi is not alerted because c is still false when it executes the second operand of &&, can someone explain how the boolean operands in if condition are executed and in what order?
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.
I believe this is just a precedence issue –
&&is binding tighter than=. Your code is equivalent to:So it’s assigning
cthe valuefalserather than the empty array.Try this instead:
EDIT: To address Tryptich’s comment – I did try this before posting 🙂 As CMS said, an empty array is considered true. Try this:
or even just this:
I checked the spec before posting – I was somewhat surprised that an empty array is considered true, but it is…