Course contentsShow
← JavaScript
Lesson 956 of 2,72321. DestructuringFree lesson

Destructuring with Mixed Parameters

Mix destructured and regular parameters to accept both structured and simple values.

Destructuring with Mixed Parameters

You'll learn how to combine destructured parameters with regular ones, giving you flexibility to accept both structured data and simple values in the same function.


The Core Idea

Sometimes a function needs a mix of inputs: maybe one argument is a complex object or array that benefits from destructuring, while others are simple values that work fine on their own. JavaScript lets you freely mix destructured parameters with regular parameters in the same function signature.

Think of it like ordering at a restaurant: you might order a combo meal (structured: burger, fries, drink) and also add a single side item (simple value). The order handles both together seamlessly.


How It Works

You can place destructured parameters alongside regular parameters in any order:

// Object destructuring mixed with regular parameters
function createUser(id, { name, email }, isActive) {
  console.log(`ID: ${id}`);
  console.log(`Name: ${name}`);
  console.log(`Active: ${isActive}`);
}

createUser(42, { name: 'Alice', email: 'alice@example.com' }, true);
// ID: 42
// Name: Alice
// Active: true

// Array destructuring with regular parameters
function processCoordinates(label, [x, y]) {
  console.log(`${label}: (${x}, ${y})`);
}

processCoordinates('Start', [10, 20]);
// Start: (10, 20)

The key is clarity: use destructuring where it simplifies extracting multiple values, and keep simple parameters when a single value makes sense.


Why It Matters

This pattern is common in real-world code where some data arrives structured (API responses, configuration objects) while other values are straightforward identifiers or flags.

Key Takeaway: You can freely combine destructured and regular parameters in function signatures, allowing you to handle both structured and simple data elegantly in the same function call.