๐ŸŒ
David Walsh
davidwalsh.name โ€บ destructuring-function-arguments
Destructuring and Function Arguments
April 3, 2018 - If you aren't familiar with JavaScript destructuring, it basically provides a shorter syntax for extracting an object key's value without the dot notation mess: // A sample object const myObject = { x: 1, y: 2 }; // Destructuring const { x, y } = myObject; // x is 1, y is 2 ยท The basic syntax for destructuring is fairly simple but using destructuring with function arguments can be a bit more difficult when those argument values should have default values.
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 20-destructuring-function-arguments
Extract Functions Arguments using Destructure in JavaScript | SamanthaMing.com
ES6 Destructuring is terrific at extracting value from your arguments. So the next time you see the array bracket notation, just swap them out and use the destructuring syntax instead ๐ŸŽ‰ ยท function omelette(...args) { // โŒ Old Way const egg = args[0]; const cheese = args[1]; // โœ… Better Way with Destructuring const [egg, cheese] = args; } omelette('๐Ÿฅš', '๐Ÿง€');
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ Destructuring_assignment
Destructuring - JavaScript | MDN
The destructuring syntax is a JavaScript syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. It can be used in locations that receive data (such as the left-hand side of an assignment or anywhere that creates new identifier bindings).
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ Destructuring
Destructuring - JavaScript - MDN Web Docs
The destructuring syntax is a JavaScript syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. It can be used in locations that receive data (such as the left-hand side of an assignment or anywhere that creates new identifier bindings).
๐ŸŒ
HTML Goodies
htmlgoodies.com โ€บ home โ€บ javascript
Destructuring Mixed Objects and Function Arguments in ES6 | HTML Goodies
July 21, 2022 - Objects passed to functions can be destructured within the function signature where function arguments are defined. This time, we would replicate the object structure in the arguments list: //Programmer Object containing nested elements const ...
๐ŸŒ
Plain English
plainenglish.io โ€บ home โ€บ blog โ€บ javascript โ€บ destructuring function parameters in javascript
Destructuring Function Parameters in JavaScript
April 22, 2022 - To destructure an object inside a function's parameters we place a set of curly braces inside the parentheses of the function. Inside the curly braces, we place the properties of the object which we wish to pick out.
๐ŸŒ
Go Make Things
gomakethings.com โ€บ destructuring-function-parameters-with-vanilla-js-for-better-developer-ergonomics
Destructuring function parameters with vanilla JS for better developer ergonomics | Go Make Things
February 22, 2021 - But, we use object destructuring to accept an object of values and destructure them into parameters while assigning them. function greet ({greeting, name, time}) { return `${greeting} ${name}! How are you ${time}?`; }
๐ŸŒ
Xah Lee
xahlee.info โ€บ js โ€บ js_func_arg_destructure.html
JS: Function Argument Destructure (Pattern Matching)
May 18, 2019 - // With default values for missing ... [c, restProps]; console.log(ff({ a: 1, b: 2, c: 3 })); // [ 3, { a: 1, b: 2 } ] Destructure works with function defined by keyword function and Arrow Function ....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ parameter-destructuring
Parameter Destructuring | GeeksforGeeks
June 12, 2022 - Destructuring in JavaScript is used to unpack or segregate values from arrays or properties from object literals into distinct variables, thus it allows us to access only the values required.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ swlh โ€บ javascript-use-destructuring-assignment-over-function-parameters-7d22b9f9b851
JavaScript: Use Destructuring Assignment over Function Parameters | by Kris Guzman | The Startup | Medium
July 16, 2019 - Destructuring Assignment with objects is just a way to take any JavaScript object: And pull out the parameters we want into its own variable:
๐ŸŒ
W3Schools
w3schools.com โ€บ JS โ€บ js_destructuring.asp
JavaScript Destructuring
You can end a destructuring syntax with a rest property. This syntax will store all remaining values into a new array:
Top answer
1 of 3
22

No (mostly)


From the grammar:

It's hard to prove a negative, so I had to go to the grammar.

Typescript, as far as I'm aware, does not provide any extra destructuring power that javascript does not, so I'll just answer this for javascript.

In the ES6 grammar, there's no way for a single function parameter to be both destructed and given a name in the parameter list, in one parameter.

If you look at the ES6 grammar for FormalParameter, which is one of the things in an argument list, you'll find it can only be a BindingElement, which is either a SingleNameBinding or a BindingPattern โ€” not both. Binding patterns can only do destructuring and single name bindings can only assign to one value, so there's no way to do both.

(Note the grammar I linked is just a gist someone put on github. I don't think someone would post a misleading ES6 grammar on github, but if you're skeptical you can always check the less convenient official grammar.)

It's possible there's some other wild way to do this that I missed, but I've never seen it before and would be very surprised.


If you really want to...

You're "best way you can think of" is the best way I can think of too. You should do that.

I don't like answering "no", though, so if you really want to get it all in the parameter list, you can do something unpleasant instead. If you do:

function assignAndDestructure(props, { foo, bar } = props) {
    // props, foo, and bar will all be assigned
}

which kind of fits your criteria. However, it creates an optional second parameter the caller can abuse to mess up your destructuring. You can hide it by assigning it to a type that doesn't have that parameter in Typescript, but it's still risky.


In summary, there's no good way to do it, but there is a bad way. Go with your mentioned "best you can think of."

2 of 3
13

I don't understand why anybody came up with this answer... You always have a reference to the parameter in arguments.

function _test({ a, b }){ 
  var arg = arguments[0];
  console.log("a=",a,"b=",b,"arg=",arg);
}

When tested produces this output:

_test({ a:23, b:"asd", c:"$" })
// a= 23 b= asd arg= { a: 23, b: 'asd', c: '$' }

In your case it could be done this way.

export function MyCompoment({
       title, 
       foo, 
       bar
    }) {
    const props = arguments[0];
    const classes = useStyles(props); 
    return <div> title: {title}, ...</div>
}
๐ŸŒ
Fsjs
fsjs.dev โ€บ destructuring-function-arguments-cleaner-approach
Destructuring Function Arguments: A Cleaner Approach โ€” Full Stack Javascript Developer
Airbnb JavaScript Style Guide - https://github.com/airbnb/javascript ยท Destructuring function arguments gives you clearer, safer APIs. It reduces caller errors, makes defaults obvious, and helps your code evolve without breaking call sites.
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ data types
Destructuring assignment
February 26, 2026 - We can pass parameters as an object, and the function immediately destructurizes them into variables:
๐ŸŒ
Jstips
jstips.co โ€บ en โ€บ javascript โ€บ use-destructuring-in-function-parameters
Use destructuring in function parameters
February 12, 2016 - Destructuring assignment with default parameters hides all the above to a certain extent: var sayHelloTimes2 = function({ name = "Anony", surname = "Moose" } = {}, times) { console.log(`Hello ${name} ${surname}! I've seen you ${times} times before.`); }; sayHelloTimes2({ name: "Pam" }, 5678) // -> Hello Pam Moose!
๐ŸŒ
JavaScript in Plain English
javascript.plainenglish.io โ€บ destructuring-function-parameters-d110c59d7b8c
Destructuring Function Parameters in JavaScript | JavaScript in Plain English
April 25, 2022 - To destructure an object inside a function's parameters we place a set of curly braces inside the parentheses of the function. Inside the curly braces, we place the properties of the object which we wish to pick out. Below is an example using an arrow function.
๐ŸŒ
Simonsmith
simonsmith.io โ€บ destructuring-objects-as-function-parameters-in-es6
Destructuring objects as function parameters in ES6 | simonsmith.io
July 28, 2015 - function myFunc() { var opts = arguments[0] === undefined ? {} : arguments[0]; var name = opts.name === undefined ? 'Default user' : opts.name; var age = opts.age === undefined ?
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ references โ€บ javascript โ€บ destructuring
JavaScript destructuring Operator: How It Works, with Examples
June 23, 2026 - Destructure function parameters for named, self-documenting arguments with defaults. Provide defaults for properties that might be missing: const { x = 0 } = obj. Use the rest pattern to collect remaining items: const [first, ...rest] = arr. Wrap object destructuring assignments to existing variables in parentheses: ({ a } = obj).