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

188
Vistas
How to redeclare function parameter if it is not actually passed into function?

What is the best way to redeclare a function parameter if it is not actually passed into the function?

function testVariable(foo, bar) {
    bar = bar ? bar : foo; // <--
    return bar;
};

const myFinalValue = testVariable("testValue");

I want to do this to ensure that bar has a value before I continue my automation (return, in this example).

Do I have to declare a new variable name or is it possible to overwrite the given parameter?

If I overwrite that parameter, will the overwritten variable become global if no value has been passed for that parameter into the function (per the example)?

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

0

Just use defaults, and then check if the variable is the default, if it is then do whatever you want

function testVariable(foo, bar = foo) {
    return bar;
};

const myFinalValue = testVariable("testValue");
console.log(myFinalValue);

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