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

174
Vistas
Function default object, props with default values are undefined

I am working on a function and when I set all of the required inputs as object props and some of them with default values, those that I gave default values to are undefined.

Basically, I want to create some of the properties of the object required and others not.

The issue is that, if I provide a value to containerClassName for example, all of the props that have default values become undefined and I can't figure out why?

This will log all default values, no problems

beforeAfterComparison()

This will log undefined for all of them

beforeAfterComparison({ containerClassName: "someClassName" })

function beforeAfterComparison(
  {
    containerClassName,
    beforeImageUrl,
    afterImageUrl,
    containerIndex,
    lineWidth,
    lineColor,
    circleDiameter,
    circleColor,
  } = {
    containerIndex: 0,
    lineWidth: 2,
    lineColor: "black",
    circleDiameter: 50,
    circleColor: "lightgray",
  }
) {
  console.log(containerIndex);
  console.log(lineWidth);
  console.log(lineColor);
  console.log(circleDiameter);
  console.log(circleColor);
}

beforeAfterComparison();
console.log("-------------------");
beforeAfterComparison({ containerClassname: "someClassName" });

I am expecting that in both cases I should get my default values.

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

0

I think the syntax is wrong. Try this,

 function beforeAfterComparison(
  {
    containerClassName,
    beforeImageUrl,
    afterImageUrl,
    containerIndex = 0,
    lineWidth = 2,
    lineColor = "black",
    circleDiameter = 50,
    circleColor = "lightgray",
  } = {}) {
  console.log(containerIndex);
  console.log(lineWidth);
  console.log(lineColor);
  console.log(circleDiameter);
  console.log(circleColor);
}
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