Why no ability to skip arguments at calling functions?

var f = (a, b) => a ? a: b;
f(, 4);

Can it be added?

You have that ability already:

f(undefined, 4);

It is not it. It isn't skippable. If you have 10 arguments, it will be too long.
Interesting whether opening a thread about this in Ideas is just a coincidence: Proposal: Skip arguments passed to function

I'd probably try to look into resolving why you'd have to do such a thing to begin with. But the JavaScript language shouldn't just introduce a feature just because it would make one person's ability to handle poorly-designed code easier for them to manage.

It is not poorly-designed. It works for destruction (var [, a] = [3, 4]), and I got a question why no this for functions.
I suppose that skipping arguments is a quite common situation, even if to talk about built-in functions (like splice()).

It's not common on well-designed APIs, though, which is the point. (splice is a terrible API)

Skipping this at bind() is quite common.
But it is more about user-defined functions.

If you're not setting the receiver, why would you use bind or call or apply at all?

call, apply - yes, but bind - no.

function mul(a, b) {
  return a * b;
}

let double = mul.bind(null, 2);

console.log(double(3)); // = mul(2, 3) = 6
console.log(double(4)); // = mul(2, 4) = 8
console.log(double(5)); // = mul(2, 5) = 10

(b) => mul(2, b) is much simpler.

That was an example from a textbook :)

But it wasn't so.
bind() - from Chrome 7.
Arrow functions - from Chrome 45.
So bind(null, 2) could be kind of a standard thing.

Certainly it's what you used to have to do - but none of your proposal ideas would work in older browsers anyways. In modern or transpiled JS, you always have arrow functions.

Lets return to the question: since it works in var [, , a], why not f(, , a)?

FWIW you can do:

f(...[, , a]);

I know. It is too bulky.
Does f(, , a) have any prospects?

FWIW array literals and array destructuring have different meanings for empty slots. Empty slots in arrays mean no elements are created for those indices. In destructuring, it means no assignments are made for the values at those indices. This is different from having undefined in those locations since for arrays, that would add an element with the value of undefined, and with destructuring that would assign to a variable named "undefined". In the case of function arguments, there'd be no discernible difference between having an empty slot and having undefined.

1 Like

Yeah, I know.
But it returns the same undefined in both cases:

[,][0];
[undefined][0];

So "there'd be no discernible difference between having an empty slot and having undefined" is ok.
arguments may have empty slots instead (I checked, and deleted slots become empty). But I don't see why it can be needed.

It looks like if empty slots, initializations of arguments (local variables) shouldn't be done at all, what is probably not suitable.