Skip to main content Link Search Menu Expand Document (external link)

&& : 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


  <div class="eligible">
    <p>✓ Eligible to drive</p>
  </div>

  <div class="not-eligible">
    <p>Not eligible to drive</p>
    
      <p>Reason: Must be 18 or older</p>
    
    
      <p>Reason: Valid license required</p>
    
  </div>

Data:

doc.Params["model"] = new {
    age = 20,
    hasLicense = true
};

Output:

<div class="eligible">
  <p>✓ Eligible to drive</p>
</div>

Multiple Conditions


  <div class="status-valid">
    <h3>Account Status: Active</h3>
    <p>All requirements met</p>
  </div>

  <div class="status-incomplete">
    <h3>Account Incomplete</h3>
    <ul>
      <li>Account not activated</li>
      <li>Payment required</li>
      <li>Verification pending</li>
    </ul>
  </div>

Range Check


  <span class="age-group">Teenager</span>

  <span class="age-group">Adult</span>

  <span class="age-group">Other</span>

Data:

doc.Params["model"] = new {
    age = 17
};

Output:

<span class="age-group">Teenager</span>

Stock and Price Validation


  
    <div class="product-available">
      <h3></h3>
      <p>Price: $</p>
      <p>Stock: </p>
      <button>Add to Cart</button>
    </div>
  

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


  <div class="priority-critical">
    <strong>CRITICAL PRIORITY</strong>
  </div>

  <div class="priority-high">
    <strong>High Priority</strong>
  </div>

  <div class="priority-medium">
    <strong>Medium Priority</strong>
  </div>

  <div class="priority-low">
    <strong>Standard</strong>
  </div>

Date Range Validation


  <div class="active-period">
    <p>✓ Currently Active</p>
  </div>

  <div class="inactive-period">
    <p>Not currently active</p>
  </div>


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

See Also