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

208
Views
What JS feature allows this to run on StackOverflow Snippet but not node

The following code will execute properly in the sandbox:

const concatR = function(arr, ...args) {
    let arr2 = (unnest = elem => !Array.isArray(elem) ? elem : elem.flatMap(unnest))(args);
    return arr.concat(arr2);
};
let x2 = concatR([1,2,3], 'hello', 'new', [1,2,3], [1,2,[3,4]]);
console.log(x2);

However, on my VS Code with Node.js v14.18.0, it gives an error:

ReferenceError: unnest is not defined

Is there a certain feature that (I think?) allows a variable definition to pass a named arrow function, or what feature exists in the code sandbox that isn't on my local machine? Locally, I have to separate the statements:

const concatR = function(arr, ...args) {
    const unnest = elem => !Array.isArray(elem) ? elem : elem.flatMap(unnest);
    let arr2 = unnest(args);
    return arr.concat(arr2);
};
let x2 = concatR([1,2,3], 'hello', 'new', [1,2,3], [1,2,[3,4]]);
console.log(x2);

about 4 years ago · Juan Pablo Isaza
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!