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:
![JavaScript if and condition](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2022/07/JavaScript-if-and-condition.jpg?resize=180%2C97&ssl=1)
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