> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Logical AND Assignment

The logical AND assignment (`&&=`) operator assigns the value of its right operand to its left operand only if the left operand evaluates to a truthy value. It combines logical AND (`&&`) short-circuiting evaluation with variable assignment.

## Syntax

```javascript theme={"dark"}
leftExpr &&= rightExpr
```

## Mechanical Equivalence

The `&&=` operator is logically equivalent to the following expression:

```javascript theme={"dark"}
leftExpr && (leftExpr = rightExpr);
```

It is a common misconception to equate `x &&= y` with `x = x && y`. While the resulting value is often the same, the underlying execution differs significantly due to **short-circuiting**:

* In `x = x && y`, the assignment operation *always* occurs, regardless of whether `x` is truthy or falsy.
* In `x &&= y`, if `x` is falsy, the assignment operation is entirely skipped. This prevents unnecessary setter invocations and avoids triggering side effects associated with property assignment.

## Evaluation Rules

1. The JavaScript engine evaluates `leftExpr`.
2. It determines the boolean coercion (truthiness) of the evaluated `leftExpr`.
3. **If `leftExpr` is truthy:** The engine evaluates `rightExpr` and assigns the resulting value to `leftExpr`.
4. **If `leftExpr` is falsy:** The engine short-circuits. `rightExpr` is never evaluated, no assignment takes place, and `leftExpr` retains its original value.

*(Note: Falsy values in JavaScript are `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, and `NaN`. All other values are truthy.)*

## Code Visualization

**Truthy Evaluation (Assignment Occurs):**

```javascript theme={"dark"}
let x = 5;      // 5 is truthy
x &&= 10;       // x is truthy, so 10 is assigned to x
console.log(x); // 10
```

**Falsy Evaluation (Short-Circuiting):**

```javascript theme={"dark"}
let y = 0;      // 0 is falsy
y &&= 10;       // y is falsy, assignment is skipped
console.log(y); // 0
```

**Proof of Short-Circuiting:**

```javascript theme={"dark"}
let z = null;

// The function on the right is never invoked because 'z' is falsy.
z &&= (function() {
    console.log("Right operand evaluated");
    return "new value";
})();

console.log(z); // null
```

## Return Value

The `&&=` expression returns the final value of `leftExpr` after the operation completes. If an assignment occurred, it returns the value of `rightExpr`. If it short-circuited, it returns the original falsy value of `leftExpr`.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor JavaScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
