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

183
Vistas
Default params in JavaScript

I want to create a function with default params, but I want to use one default param and then use a custom value for the following one. For instance,

function greet(name, greeting = 'Hey', question = 'How are you?') {
    console.log(`${greeting}, ${name}! ${question}`);
  }

greet('Jack', , 'You good?'); // tried this, doesn't work :(

What if I wanted to say, "Hey, Jack! You good?", where I use the default for the first param with a default value, but not the second? I have tried calling the function with nothing between the commas in the function call. Is there a way to do this in JS without explicitly passing 'Hey', the defined default value, to the param that has a default already assigned?

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

0

function greet(name, greeting = 'Hey', question = 'How are you?') {
    console.log(`${greeting}, ${name}! ${question}`);
  }

greet('Jack',undefined , 'You good?');

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can pass undefined for the second param. It should work as you expect it to be.

greet('Jack', undefined, 'You good?');
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