&& : Logical AND Operator
On this page
Summary
Combine two boolean expressions. Returns true only if both operands are true.
Syntax
Precedence
Priority level in expression evaluation (1 = highest, 10 = lowest): 9
Evaluated after: ^, *, /, %, +, -, <, <=, >, >=, ==, !=, ??
Evaluated before: ||
Operands
| Position | Type | Description |
|---|---|---|
| Left | Boolean | First condition to evaluate |
| Right | Boolean | Second condition to evaluate |
Returns
Type: Boolean
true if both operands are true, false otherwise.
Truth Table
| Left | Right | Result |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
Examples
Driving Eligibility
Data:
doc.Params["model"] = new {
age = 20,
hasLicense = true
};
Output:
<div class="eligible">
<p>✓ Eligible to drive</p>
</div>
Multiple Conditions
Range Check
Data:
doc.Params["model"] = new {
age = 17
};
Output:
<span class="age-group">Teenager</span>
Stock and Price Validation
Data:
doc.Params["model"] = new {
maxBudget = 100,
products = new[] {
new { name = "Widget A", price = 49.99m, stock = 10 },
new { name = "Widget B", price = 149.99m, stock = 5 },
new { name = "Widget C", price = 79.99m, stock = 0 }
}
};
Output:
<div class="product-available">
<h3>Widget A</h3>
<p>Price: $49.99</p>
<p>Stock: 10</p>
<button>Add to Cart</button>
</div>
Priority Classification
Date Range Validation
Notes
- Both conditions must be true for result to be true
- Uses short-circuit evaluation: if first condition is false, second is not evaluated
- Can chain multiple AND conditions:
a && b && c - Use parentheses for complex expressions:
(a && b) || (c && d) - Commonly combined with comparison operators
- Has higher precedence than OR (
||) operator - Note:
!(NOT) operator is not supported - use!=instead