Here is how I mention two conditions if this or this
if (Type == 2 && PageCount == 0) || (Type == 2 && PageCount == '') PageCount= document.getElementById('<%=hfPageCount.ClientID %>').value; }
Using either “&&” or “||” i.e. logical AND or logical OR operator or combination of can achieve 3 conditions in if statement JavaScript.
We can also write multiple conditions inside a single if statement with the help of the logical operators && and | | . The && operators will evaluate if one condition AND another is true. Both must be true before the code in the code block will execute.
When you combine each one of them with an IF statement, they read like this: AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False) OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False) NOT – =IF(NOT(Something is True), Value if True, Value if False)
Use two if statements if both if statement conditions could be true at the same time. In this example, both conditions can be true. You can pass and do great at the same time. Use an if/else statement if the two conditions are mutually exclusive meaning if one condition is true the other condition must be false.
just add them within the main bracket of the if statement like
if ((Type == 2 && PageCount == 0) || (Type == 2 && PageCount == '')) { PageCount= document.getElementById('<%=hfPageCount.ClientID %>').value; }
Logically this can be rewritten in a better way too! This has exactly the same meaning
if (Type == 2 && (PageCount == 0 || PageCount == '')) {
Here is an alternative way to do that.
const conditionsArray = [ condition1, condition2, condition3, ] if (conditionsArray.indexOf(false) === -1) { "do somthing" }
Or ES7+
if (!conditionsArray.includes(false)) { "do somthing" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With