var foo=[0];
if(foo) alert('first');
if(foo==true) alert('second');
Tell me please, why the second alert doesn’t work? In first alert foo casts to Boolean, so
Boolean(foo);
//true
If “foo” is “true”, why doesn’t the second alert work?
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.
Here,
if( foo) alerts because foo isn’t null and the condition evaluates to true.
However, this doesn’t mean that foo itself is equal to true, hence the second alert doesn’t show.