Using the AND && in the if statement will evaluate 2 conditions, if both are true then only if the block code executes. The &&
the operator is only true if both the left and right sides of the &&
are true.
JavaScript if and
Simple example code use AND statement in if with javascript.
<!DOCTYPE html>
<html>
<body>
<script>
var age = 18;
if ((age >= 14) && (age < 19)) {
console.log("Eligible.");// executed if condition is true
} else {
console.log("Not eligible."); // executed if condition is false
}
</script>
</body>
</html>
Output:
Do comment if you have any doubts o suggestions on this Js if statement topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version