> ## 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 Destructured Parameter

A destructured parameter is a JavaScript feature that allows a function to unpack properties from objects or elements from arrays passed as arguments directly within the function signature. It evaluates the incoming argument and binds the extracted data to distinct, locally scoped variables during the function invocation phase.

## Object Destructured Parameters

Object destructuring in parameters matches the keys of the incoming object argument to variable names defined in the signature.

**Basic Syntax:**

```javascript theme={"dark"}
function processUser({ name, age }) {
  console.log(name, age);
}
```

**Aliasing (Renaming Variables):**
You can bind an extracted property to a variable with a different identifier using the `key: variableName` syntax.

```javascript theme={"dark"}
function processUser({ id: userId, name: userName }) {
  console.log(userId, userName);
}
```

**Default Values:**
Default values are assigned if the extracted property is strictly `undefined`.

```javascript theme={"dark"}
function processUser({ role = 'guest', status = 'active' }) {
  console.log(role, status);
}
```

## Array Destructured Parameters

Array destructuring in parameters relies on the iterable protocol, binding variables based on their positional index in the incoming array argument.

**Basic Syntax:**

```javascript theme={"dark"}
function processCoordinates([x, y, z]) {
  console.log(x, y, z);
}
```

**Elision (Skipping Elements):**
Commas can be used to skip indices without binding them to variables.

```javascript theme={"dark"}
function processCoordinates([x, , z]) {
  console.log(x, z);
}
```

## Advanced Mechanics

**Nested Destructuring:**
Destructuring can traverse deeply nested structures directly within the parameter signature.

```javascript theme={"dark"}
function processPayload({ metadata: { timestamp, source } }) {
  console.log(timestamp, source);
}
```

**Rest Binding:**
The rest operator (`...`) collects all remaining enumerable properties (for objects) or remaining iterable elements (for arrays) into a new object or array. It must be the final binding in the destructured pattern.

```javascript theme={"dark"}
function processRecords([firstRecord, ...remainingRecords]) {
  console.log(firstRecord, remainingRecords);
}

function processConfig({ theme, ...otherSettings }) {
  console.log(theme, otherSettings);
}
```

**Parameter Fallbacks (Preventing TypeErrors):**
If a function with a destructured parameter is invoked without an argument, the JavaScript engine attempts to destructure `undefined`, resulting in a `TypeError`. To prevent this, the entire destructured parameter can be assigned an empty object or array as a default fallback.

```javascript theme={"dark"}
// Throws TypeError if called as initialize()
function initialize({ port, host }) {}

// Safely defaults to an empty object, then applies property defaults
function initialize({ port = 8080, host = 'localhost' } = {}) {}
```

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