> ## 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 Default Value Destructuring

Default value destructuring is a syntax mechanism in JavaScript that assigns a fallback expression to a variable during object or array destructuring. This fallback is evaluated and assigned exclusively when the targeted property or element in the source structure is strictly `undefined` or does not exist.

## Trigger Condition

The default value is only applied if the extracted value is strictly equal to `undefined` (`value === undefined`). Falsy values such as `null`, `0`, `false`, or `""` (empty string) are considered valid values and will bypass the default assignment.

## Object Destructuring

In object destructuring, the default value is assigned using the assignment operator (`=`) immediately following the property identifier.

```javascript theme={"dark"}
const source = { a: 1, b: undefined, c: null };

const { 
  a = 10, 
  b = 20, 
  c = 30, 
  d = 40 
} = source;

// a: 1  (exists, bypasses default)
// b: 20 (strictly undefined, triggers default)
// c: null (is not undefined, bypasses default)
// d: 40 (does not exist, implicitly undefined, triggers default)
```

## Array Destructuring

In array destructuring, defaults are applied based on the iterable's positional indices. Out-of-bounds indices yield `undefined`, thereby triggering the default value.

```javascript theme={"dark"}
const sequence = [100, undefined, null];

const [
  first = 0, 
  second = 0, 
  third = 0, 
  fourth = 0
] = sequence;

// first: 100
// second: 0 (strictly undefined)
// third: null (is not undefined)
// fourth: 0 (out of bounds, implicitly undefined)
```

## Aliasing with Default Values

When renaming a variable during object destructuring (aliasing), the default value assignment must follow the new identifier. The syntax pattern is `sourceProperty: targetVariable = defaultValue`.

```javascript theme={"dark"}
const record = { identifier: undefined };

const { identifier: id = 'default-id' } = record;

// id: 'default-id'
```

## Lazy Evaluation

Default value expressions are evaluated lazily. The expression on the right side of the `=` is only executed if the default value is actually required.

```javascript theme={"dark"}
const computeFallback = () => {
  console.log("Evaluated!");
  return 99;
};

// computeFallback() is NOT called because 'value' is defined
const { value = computeFallback() } = { value: 42 }; 

// computeFallback() IS called because 'missing' is undefined
const { missing = computeFallback() } = {}; 
```

## Nested Destructuring with Defaults

Default values can be applied at multiple levels of a nested destructuring assignment. To prevent a `TypeError` when attempting to destructure properties from an `undefined` parent, a default empty object (`{}`) is often assigned to the parent level.

```javascript theme={"dark"}
const payload = { data: undefined };

const { 
  data: { 
    status = 'inactive' 
  } = {} 
} = payload;

// status: 'inactive'
// The parent 'data' defaults to {}, allowing 'status' to be safely destructured and defaulted.
```

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