Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!