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

157
Vistas
Confusing points in JS destructuring not understood

i was taking lessons on ES6 key features but this snippet is troubling my common sense, how does javascript resolve ",b" to be the 2nd item in the return array of the foo function does b in the case implicitly mean 2nd item and z would mean 26th item ?? See code snippet below ...

    function foo() {
 return [1,2,3];
}


function bar() {
 return {
 x: 4,
 y: 5,
 z: 6
 };
}


var [,b] = foo();
var { x, z } = bar();
console.log( b, x, z );

// 2 4 6

Code Snippet

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

0

The lettering does not matter. What matters is the comma.

var [b] would destructure the first element from the array returned by foo().

var [,b] destructures the second element from the array

var [, , b] would destructure the third element.

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