How to Combine Multiple Javascript Conditions into One Condition

By: Dusty Arlia
Published on Monday, May 13, 2013, 06:24 PM
Last Updated on Friday, July 10, 2015 at 5:57 PM
Total Updates: 2

Whenever you combine multiple conditions into one condition, that condition is called a complex condition. In order to combine conditions, make use of the logical AND operator (&&) and/or the logical OR operator (||).

Here is an example of a complex condition using the logical AND operator:

if ((price > 5) && (weight < 20)) {
alert('Shipping is free!');
}

Here is an example of a complex condition using the logical OR operator:

if (customer == 'senior' || customer == 'veteran' || customer == 'Chuck Norris') {
alert('You get 50% off!');
}

Comments:

Ad: