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

589
Views
ESLint complains if I assign a function parameter, but not if I run a function that changes the function parameter. Why?

The following code selects all div elements and changes their class to 'test. ESLint complains about assignment to property of function parameter:

  [...document.getElementsByTagName('div')].forEach(div => {
    div.className = 'test';
  });

However, if I mutate the parameter by running a function or method, then I get no complaints. The following code does the exact same thing as the code that gets complained about, but is less efficient and less readable:

 [...document.getElementsByTagName('div')].forEach(div => {
    div.classList.remove(...div.classList);
    div.classList.add('test');
  });

Why is one okay but the other is not?

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

0

ESLint's no-param-reassign rule includes prohibiting assignment of function arguments' properties. But it has a props option that you could configure to false if you want to keep the rule more generally but also allow it to mutate function arguments without reassigning them.

As the documentation page explains, the rule exists because reassigning (or mutating) function arguments will also mutate the arguments object, which may be confusing.

There's no way for ESLint to know if an object's method is going to mutate that object, which is why it can't error when you call a method that mutates a function argument.

In my experience, this side effect of mutating arguments is pretty rarely an issue, especially when you're just mutating function arguments instead of reassigning them. What you're doing in this example clearly isn't going to cause the sort of issue this rule is meant to help with.

Personally, this is a rule that I turn off in my 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!