Categories
JavaScript Answers

How to avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript?

Spread the love

Sometimes, we want to avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript.

In thiks article, we’ll look at how to avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript.

How to avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript?

To avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript, we can assign the parameter to a variable.

For instance, we write

const f = (el) => {
  const theElement = el;
  theElement.expand = {};
};

to create the f function.

In it, we assign el to the theElement variable.

And then we add the theElement.expand property to it.

Conclusion

To avoid no-param-reassign ESLint error when setting a property on a DOM object with JavaScript, we can assign the parameter to a variable.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *