Can I make this statement shorter?
if(abc=='value1' || abc=='value2' || abc=='value3') {//do something}
to make it look similar to this:
if(abc=='value1' || 'value2' || 'value3'){//do something}
Thanks.
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.
You have a couple options:
switchstatement.The second form is not valid Javascript syntax.
(2) is something like:
(3) is:
Personally I’m not a huge fan of this from a readability point of view but it’s a reasonable approach with a large number of values.
I don’t necessarily recommend this but it might be an option in certain circumstances. If you’re only dealing with three values stick with:
as it’s much more readable.