Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
An argument with default value precedes non-default argument in JavaScript

In JavaScript it's possible to define a function like this:

function func(a = 10, b)
{
  return a + b;
}

How does one call this function by only specifying the value for b?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It'd only be possible by explicitly passing undefined, and by also providing a default for the second argument.

function func(a = 10, b) {
  return a + b;
}

console.log(func(undefined, 5));

But this is quite weird - it's very confusing. I'd highly recommend not doing this at all - either put the arguments with default values at the end, or in an object.

function func({ a = 10, b }) {
  return a + b;
}

console.log(func({ b: 5 }));

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are okay with currying the first parameter:

bind saves the function with the arguments supplied, so when one calls it, it calls it with the arguments applied. The first argument is what to bind this to, so the second argument will bind to a:

function func(a, b) { 
    return a + b;
}

newFunc = func.bind(null, 10)
newFunc(2)
12
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda