How can I check multiple conditions in a single JavaScript if statement efficiently