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

191
Views
Why this setState is like this and how this is working?

Sorry I don't know how to search this kinda problem and I didn't find any answer to this but I'm so confused with this code, its a setState function for an OTP verification :

setCode((currCode) =>
  currCode
  .split('')
  .map((ch, i) => (i !== idx ? ch : isCharNumber ? val : isEmpty ? '_' : ch))
  .join(''),
);

I understand the map part I'm just wondering about that comma "," after the join function. why? if I delete that the code works but ESlint tell me to put that at the end. does it return an object? it just goes through the state which is "____" (four underscores) and change each _ to digit. I really appreciate if someone explain this to me and tell me how can I search and look for this kind of confusions. ty

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

0

does it return an object?

No.

I'm just wondering about that comma "," after the join function. why?

In modern JavaScript, it's optional to have a comma after the last argument in a function call (and after the last parameter in a function parameter list), like this:

example(
    firstArg,
    secondArg,
    thirdarg,
  //        ^−−−−−−−−−−−− optional
)

It makes it convenient when adding/removing arguments later not to have to worry about adding/removing a comma.

That's what's going on in your code, there's a single argument to setCode (the arrow function), followed by a comma.

if I delete that the code works but ESlint tell me to put that at the end.

ESLint can be configured to require trailing commas in function argument lists; apparently it's configured that way in your setup. If you don't like the rule, you can turn it off (in private projects) or discuss it with your team (in team projects).

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!