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

123
Views
Possible to assign function parameter via destructuring?

Is it possible to do something like the following in js?

function Something( Point{PointX, PointY}   ) {
    console.log('Point', Point);
    console.log('PointX,PointY', PointX, PointY);
}
Something([1,2]);

If so, what would be the proper way to do that?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

function Something(Point) {
  const [PointX, PointY] = Point
  console.log('Point', Point)
  console.log('PointX,PointY', PointX, PointY)
}
about 4 years ago · Juan Pablo Isaza Report

0

Is this what you need?

function Something([PointX, PointY]) {
    console.log('PointX,PointY', PointX, PointY);
}

You can destructure both arrays (function([x, y]) and objects (function({ x, y })).

about 4 years ago · Juan Pablo Isaza Report

0

Sure, but make sure the keys match up to do the destructuring assignment for an object, such as:

function Something({x,y}) {
    console.log('PointX, PointY', x, y);
}
Something({x: 1, y: 2});

In terms on naming and also assigning it to the outer object, perhaps you can do something like this instead:

function Something(Point) {
    const {x,y} = Point;
    console.log('Point, PointX, PointY', Point, x, y);
}
Something({x: 1, y: 2});

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!