Javascript Conditional AND and OR
The && operator performs the conditinal AND operation. It compbines two boolean values and the result is true if both the operands are true. The conditional OR || operator returns true if either of the two operands are true.
Consider a practical example , where we check a patient's seriousness by checking his weight and blood sugar level. An excessive body weigh and high blood sugar level triggers serious health condition and he must see a doctor.
|
If you compile and run this program, you will get the output as follows
You are overweight and have high blodd glucose. You must see doc |
You may like to try this example online here
The || operator performs the conditinal OR operation. It evaluates two boolean values and the result is true if either one or both the operands are true. Consider a practical example , where we check a patient's Systoloc blood pressure and fasting blood sugar level. We trigger an alarm and ask the patient to see a doctor if either of the two is excessive.
|
If you compile and run this program, you will get the output as follows
You should see a doctor |
You may like to try this example online here
The NOT operator is a unary operator and take a single boolean arguments and inverts it. See the folllowing example where we have tried to print true if the patient is healthy ( depending upon both his blood pressure and blood glucose being under control).
|
If you compile and run this program, you will get the output as follows
You should see a doctor |
You may like to try this example online here