# Why no ability to skip arguments at calling functions?

**URL:** <https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137>\
**Category:** I have questions\
**Created:** [September 12, 2024, 11:10am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137 "2024-09-12T11:10:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 11:10am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/1 "2024-09-12T11:10:37Z")

</div>

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

```

Can it be added?

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [September 12, 2024, 11:44am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/2 "2024-09-12T11:44:53Z")

</div>

You have that ability already:

```js
f(undefined, 4);

```

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 3:33pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/3 "2024-09-12T15:33:29Z")

</div>

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](https://es.discourse.group/t/proposal-skip-arguments-passed-to-function/2138)

---

<div class="post-metadata">

**Author:** ![ke67](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@ke67](https://es.discourse.group/u/ke67)\
**Post date:** [September 12, 2024, 7:06pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/4 "2024-09-12T19:06:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 7:12pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/5 "2024-09-12T19:12:16Z")

</div>

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()`).

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [September 12, 2024, 8:03pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/6 "2024-09-12T20:03:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 8:21pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/7 "2024-09-12T20:21:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [September 12, 2024, 8:52pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/8 "2024-09-12T20:52:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 8:56pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/9 "2024-09-12T20:56:07Z")

</div>

`call`, `apply` - yes, but `bind` - no.

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

```

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [September 12, 2024, 9:44pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/10 "2024-09-12T21:44:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 9:57pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/11 "2024-09-12T21:57:24Z")

</div>

That was an example from a textbook :)

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 12, 2024, 10:05pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/12 "2024-09-12T22:05:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [September 12, 2024, 10:37pm UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/13 "2024-09-12T22:37:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 13, 2024, 6:28am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/14 "2024-09-13T06:28:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [September 13, 2024, 6:43am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/15 "2024-09-13T06:43:18Z")

</div>

FWIW you can do:

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

```

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 13, 2024, 6:59am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/16 "2024-09-13T06:59:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/senocular/32/642_2.png) [@senocular](https://es.discourse.group/u/senocular)\
**Post date:** [September 13, 2024, 11:12am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/17 "2024-09-13T11:12:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oleedd](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/oleedd/32/2148_2.png) [@oleedd](https://es.discourse.group/u/oleedd)\
**Post date:** [September 13, 2024, 11:36am UTC](https://es.discourse.group/t/why-no-ability-to-skip-arguments-at-calling-functions/2137/18 "2024-09-13T11:36:35Z")

</div>

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

```javascript
[,][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.
