no-param-reassign
Disallow reassigning function parameters
Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object when not in strict mode (see When Not To Use It below). Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.
This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

Rule Details
This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule takes one option, an object, with a boolean property "props" , and arrays "ignorePropertyModificationsFor" and "ignorePropertyModificationsForRegex" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they’re included in "ignorePropertyModificationsFor" or "ignorePropertyModificationsForRegex" , which is an empty array by default.
Examples of correct code for the default { "props": false } option:
Examples of incorrect code for the { "props": true } option:
Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:
Examples of correct code for the { "props": true } option with "ignorePropertyModificationsForRegex" set:
When Not To Use It
If you want to allow assignment to function parameters, then you can safely disable this rule.
Strict mode code doesn’t sync indices of the arguments object with each parameter binding. Therefore, this rule is not necessary to protect against arguments object mutation in ESM modules or other strict mode functions.
This rule was introduced in ESLint v0.18.0.
Further Reading
- Rule source
- Tests source
- Assignment to property of function parameter no-param-reassign

Last updated: May 9, 2023 Reading time · 3 min

# Table of Contents
- Disabling the no-param-reassign ESLint rule for a single line
- Disabling the no-param-reassign ESLint rule for an entire file
- Disabling the no-param-reassign ESLint rule globally
# Assignment to property of function parameter no-param-reassign
The ESLint error "Assignment to property of function parameter 'X' eslint no-param-reassign" occurs when you try to assign a property to a function parameter.
To solve the error, disable the ESLint rule or create a new object based on the parameter to which you can assign properties.

Here is an example of how the error occurs.
The ESLint rule forbids assignment to function parameters because modifying a function's parameters also mutates the arguments object and can lead to confusing behavior.
One way to resolve the issue is to create a new object to which you can assign properties.
We used the spread syntax (...) to unpack the properties of the function parameter into a new object to which we can assign properties.
If you need to unpack an array, use the following syntax instead.
The same approach can be used if you simply need to assign the function parameter to a variable so you can mutate it.
We declared the bar variable using the let keyword and set it to the value of the foo parameter.
We are then able to reassign the bar variable without any issues.
# Disabling the no-param-reassign ESLint rule for a single line
You can use a comment if you want to disable the no-param-reassign ESLint rule for a single line.
Make sure to add the comment directly above the assignment that causes the error.
# Disabling the no-param-reassign ESLint rule for an entire file
You can also use a comment to disable the no-param-reassign ESLint rule for an entire file.
Make sure to add the comment at the top of the file or at least above the function in which you reassign parameters.
The same approach can be used to disable the rule only for a single function.
The first comment disables the no-param-reassign rule and the second comment enables it.
If you try to reassign a parameter after the second comment, you would get an ESLint error.
# Disabling the no-param-reassign ESLint rule globally
If you need to disable the no-param-reassign rule globally, you have to edit your .eslintrc.js file.

If you only want to be able to assign properties to an object parameter, set props to false instead of disabling the rule completely.
The following code is valid after making the change.
If you use a .eslintrc or .eslintrc.json file, make sure to double-quote the properties and values.
If you want to only allow assignment to object parameters, use the following line instead.
Make sure all properties are double-quoted and there are no trailing commas if your config is written in JSON.
# Additional Resources
You can learn more about the related topics by checking out the following tutorials:
- eslint is not recognized as an internal or external command
- Plugin "react" was conflicted between package.json » eslint-config-react-app
- React: Unexpected use of 'X' no-restricted-globals in ESLint
- TypeScript ESLint: Unsafe assignment of an any value [Fix]
- ESLint error Unary operator '++' used no-plusplus [Solved]
- ESLint Prefer default export import/prefer-default-export
- Arrow function should not return assignment. eslint no-return-assign
- TypeError: Cannot redefine property: X in JavaScript [Fixed]
- ESLint: disable multiple rules or a rule for multiple lines
- Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style
- Missing return type on function TypeScript ESLint error

Borislav Hadzhiev
Web Developer

Copyright © 2023 Borislav Hadzhiev
Disallow Reassignment of Function Parameters (no-param-reassign)
Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.
This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.
Rule Details
This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor" . "props" is false by default. If "props" is set to true , this rule warns against the modification of parameter properties unless they’re included in "ignorePropertyModificationsFor" , which is an empty array by default.
Examples of correct code for the default { "props" : false } option:
Examples of incorrect code for the { "props" : true } option:
Examples of correct code for the { "props" : true } option with "ignorePropertyModificationsFor" set:
When Not To Use It
If you want to allow assignment to function parameters, then you can safely disable this rule.
Further Reading
- JavaScript: Don’t Reassign Your Function Arguments
This rule was introduced in ESLint 0.18.0.
- Rule source
- Documentation source
- Skip to main content
- Skip to search
- Skip to select language
- Sign up for free
- English (US)
The arguments object
arguments is an array-like object accessible inside functions that contains the values of the arguments passed to that function.
Description
Note: In modern code, rest parameters should be preferred.
The arguments object is a local variable available within all non- arrow functions. You can refer to a function's arguments inside that function by using its arguments object. It has entries for each argument the function was called with, with the first entry's index at 0 .
For example, if a function is passed 3 arguments, you can access them as follows:
The arguments object is useful for functions called with more arguments than they are formally declared to accept, called variadic functions , such as Math.min() . This example function accepts any number of string arguments and returns the longest one:
You can use arguments.length to count how many arguments the function was called with. If you instead want to count how many parameters a function is declared to accept, inspect that function's length property.
Assigning to indices
Each argument index can also be set or reassigned:
Non-strict functions that only has simple parameters (that is, no rest, default, or destructured parameters) will sync the new value of parameters with the arguments object, and vice versa:
Non-strict functions that are passed rest , default , or destructured parameters will not sync new values assigned to parameters in the function body with the arguments object. Instead, the arguments object in non-strict functions with complex parameters will always reflect the values passed to the function when the function was called.
This is the same behavior exhibited by all strict-mode functions , regardless of the type of parameters they are passed. That is, assigning new values to parameters in the body of the function never affects the arguments object, nor will assigning new values to the arguments indices affect the value of parameters, even when the function only has simple parameters.
Note: You cannot write a "use strict"; directive in the body of a function definition that accepts rest, default, or destructured parameters. Doing so will throw a syntax error .

arguments is an array-like object
arguments is an array-like object, which means that arguments has a length property and properties indexed from zero, but it doesn't have Array 's built-in methods like forEach() or map() . However, it can be converted to a real Array , using one of slice() , Array.from() , or spread syntax .
For common use cases, using it as an array-like object is sufficient, since it both is iterable and has length and number indices. For example, Function.prototype.apply() accepts array-like objects.
Reference to the currently executing function that the arguments belong to. Forbidden in strict mode.
The number of arguments that were passed to the function.
Returns a new Array iterator object that contains the values for each index in arguments .
Defining a function that concatenates several strings
This example defines a function that concatenates several strings. The function's only formal argument is a string containing the characters that separate the items to concatenate.
You can pass as many arguments as you like to this function. It returns a string list using each argument in the list:
Defining a function that creates HTML lists
This example defines a function that creates a string containing HTML for a list. The only formal argument for the function is a string that is "u" if the list is to be unordered (bulleted) , or "o" if the list is to be ordered (numbered) . The function is defined as follows:
You can pass any number of arguments to this function, and it adds each argument as a list item to a list of the type indicated. For example:
Using typeof with arguments
The typeof operator returns 'object' when used with arguments
The type of individual arguments can be determined by indexing arguments :
Specifications
Browser compatibility.
BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
- Functions guide
- Rest parameters
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- Labs The future of collective knowledge sharing
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
adding an assign function as property to an object in NodeJs
for the sake of fun and exploring nodeJS I made an object
The problem came when I wanted to add tailnumber that is not the same for every plane but should be assigned to the plane. what is the methode?
or must I have the entire F15c as a function?
but then i cannot set the entire variables complex.
or perhaps I'm doing it wrong and should refer the variable as an individual F15 and use a different function to create it? but then how do I make that field in a way it is unassigned and waiting to be assigned (and then saves the assigned number)?
would appreciate some heads up
- What exactly are you trying to do? It is much more important question than the "how to use function". To what you are doing - it looks like that define class and pass tailnumber into the constructor is much better option. – libik Dec 20, 2017 at 16:01
- You should accept Jelmer's response below as it is complete and elegant. Just remember the concept of using this : it represents the calling object. – noderman Dec 20, 2017 at 16:05
2 Answers 2
The secret is to use this to refer to a property of the own object
var f15c = { ... tailnumber: null, setTailNumber : function(tn) { this.tailnumber=tn; } }
f15c.setTailNumber(1234); console.log(f15c.tailnumber);
Do you mean you want to set a value to a property?
var f15c = { _tailnumber: 0, set tailnumber(newtailnumber) { this._tailnumber = newtailnumber; }, get tailnumber() { return this._tailnumber } }; f15c.tailnumber = "304"; console.log(f15c.tailnumber); console.log(f15c);

- Bonus for using set and get . developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/… – noderman Dec 20, 2017 at 16:02
- 1 Still the full solution should contain a class: f15c isa plain (i guess), and an instance of f15c has a certain tail number. – Jelmer Jellema Dec 20, 2017 at 16:07
- 1 Correct. If the object is reused one might think only the new set is applied, while all references are affected. But then we dive deep :-) – noderman Dec 20, 2017 at 16:10
- what does this helps you get tailnumber() { return this._tailnumber } rather than calling the f15c.tailnumber? also, i run the code snippet and not sure why did it return in the console.log(f15c); this reply { "_tailnumber": "304", "tailnumber": "304" } ? in my case i recieve console.log(f15c); console.log(f15c.tailnumber); console: Object {fuel: 10000, IRST: true, AESA: true, speed: 2500, Ammo: Object, …} 123 – likuku Dec 20, 2017 at 16:13
- 1 what does this helps you get tailnumber() { return this._tailnumber } rather than calling the f15c.tailnumber? ---- by using set and get on the same property name, you have a real set/get behavior: f15c.tailnumber(1) sets the number and f15c.tailnumber gets it for you. Then you have to store the actual value for tailnumber somewhere else. Using _tailnumber is nice because it keeps the name for simplicity. – noderman Dec 20, 2017 at 22:48
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .
Not the answer you're looking for? Browse other questions tagged node.js function variables or ask your own question .
- The Overflow Blog
- What it’s like being a professional workplace bestie (Ep. 603)
- Journey to the cloud part I: Migrating Stack Overflow Teams to Azure
- Featured on Meta
- Moderation strike: Results of negotiations
- Our Design Vision for Stack Overflow and the Stack Exchange network
- Temporary policy: Generative AI (e.g., ChatGPT) is banned
- Discussions experiment launching on NLP Collective
- Call for volunteer reviewers for an updated search experience: OverflowAI Search
Hot Network Questions
- Protecting your engines in a space battle
- Someone I don't know contributed to my program on GitHub. Can I still present that program as my Bachelor thesis?
- Can you represent a language with a group with a small/simple generator set?
- Connect dots on a grid with one continuous line 2.0
- Are there question that science can't answer, but which philosophy can?
- How much does choice of PhD typically matter for a future career in academia?
- Why are radio telescopes often built into natural depressions?
- How to slow down while maintaining altitude
- Applying to a tenure track job at the same school two years in a row
- After putting something in my oven, the temperature drops and is super slow to increase back up despite keeping the door shut
- Can a 650 nm 250 mW diode laser remove the first layer of a PCB?
- Probability generating function and binomial coefficients
- Pre-2000 sci-fi book with FTL travel, conventional guns, and one alien species
- Turned away for medical service at private urgent care due to being enrolled in medicare even with private insurance
- Has anyone been charged with a crime committed in space?
- Usage of the word "deployment" in a software development context
- How to temporarily remove one hinge on a door with two hinges
- Are there any more ways to regain spent hit dice?
- Why are my newlines turned into \Omega?
- Analog science fact article about dimensions
- How to find files that don’t have a suffixed version?
- Is it possible to design a bottle that can always be "full"?
- Idiom for being watched after your bad actions
- If you introduce an abbreviation/acronym in the abstract, should you reintroduce it in the introduction to be safe?
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
[Solved]-Assignment to property of function parameter 'a' Eslint-Reactjs
there's no need to reassign the pos property of the function arguments ( a, b ). you should just assign a new variable ( apos, bpos ), which is a best practice, hence why eslint is complaining.
you should avoid unnecessary mutations/side-effects whenever possible in your code to prevent bugs and create an overall more efficient program architecture.
more specifically in this case..
eslint: disallow reassignment of function parameters (no-param-reassign)

you eslint is configured to not allow re-assignment of parameters, i.e if a function takes 2 arguments (a, b), then you cant re-assign these 2 variables in the function body.
to fix this error, either:
- disable the eslint rule (in your .eslintrc or just for the function)
- create new variables to avoid re-assigning to a and b (see below):
then replace references to a.pos and b.pos to apos and bpos .

Related Query
- Assignment to property of function parameter 'a' Eslint
- ESLint | Assignment to property of function parameter 'payload'
- Assignment to property of function parameter 'item'
- How to solve this assignment to property of function parameter
- React JS .map and assignment causing esLint error 'Assignment to property of function parameter. eslint(no param-reassign)'
- ESLint throws an "is missing in props validation" error when use destructuring in function parameter
- Arrow function should not return assignment Eslint
- React EsLint - Component should be written as pure function and after changed it to pure function can't read the property anymore
- useAutocomplete Uncaught TypeError: Cannot read property 'filter' of undefined or Expected an assignment or function call and instead saw expression
- sending a parameter to a function returns Cannot read property 'props' of undefined
- Set default value of property of object passed on parameter to function
- React - Changing state property value (a boolean) with a function taking a string parameter
- Why am I getting a 'Assignment to property of function parameter ..' eslinterror?
- ESLint Espected an assignment or function call and instead saw an expression on void function
- Typescript function parameter has two types, and the property of one type can't be accessed because it is not a property of the other type
- Assignment to function parameter 'state' on redux get failed to compile
- expected assignment or function call: no-unused-expressions ReactJS
- React: Expected an assignment or function call and instead saw an expression
- ESLint - Component should be written as a pure function (react prefer/stateless function)
- ESLint Must use destructuring state assignment
- ESLint broken: Rules with suggestions must set the `meta.hasSuggestions` property to `true`
- How to spy on a class property arrow function using Jest
- JSX element type 'App' is not a constructor function for JSX elements. Types of property 'setState' are incompatible
- What do curly braces around a variable in a function parameter mean
- React passing parameter with arrow function in child component
- Babel: Function parameter types in ES6
- React onClick function parameter turns into "Proxy" Object
- Uncaught TypeError: Cannot read property 'type' of undefined at start of switch function
- How to solve Eslint - Module.createRequire is not a function error?
- React: expected an assignment or function call and instead saw an expression no-unused-expressions
More Query from same tag
- AsyncStorage.setItem Callback Always Null
- Return <Promise> from get in react
- How to get the index of the selected item from a dropdown in ReactJs and material UI?
- What is the difference between FormSection and Fields
- static class function access issue withRouter typescript react
- Convert Webpack syntax to browserify syntax
- Name useState's current state after the initial state, but with the current state value
- JSX fragment content is not rendering
- trying to make clone of spotify app getting error in localhost:3000 TYPEERROR: Cannot read property 'url' of undefined
- How to query 'additional 10' results from database in a React + Express server
- how to send data from android application running on kotlin to a react js application which is opened on webview?
- Dynamically add new component
- Passing props to component after declaration in reactjs
- Change background color FullCalender react
- React/material-ui ListItem list sticky but overlapping
- random button is not working as expected (React)
- display html entity Superscript in JSX
- Understanding the meaning if >0.2% and finding the IE versions supported
- Only numbers. Input number in React
- Use CSS filters in svg image tag?
- Send date from react-date picker to backend
- Testing a nested async call react component
- React event object
- How to update state multiple times on same event using React useState hook?
- Toggle boolean value using hooks in React
- Can I modify a package from node_modules?
- How not to lose the values of an array in React?
- Identify selected date range in react-date-range
- Why is my .glb file not included in the dist/assets folder in react.js and three.js?
- I retrieve two errors when trying to implement nav bar from internet
Copyright 2023 www.appsloveworld.com . All rights reserved.
Class DataFlow :: ParameterNode
A data flow node corresponding to a parameter.
For example, x is a parameter of function f(x) {} .
When a parameter is a destructuring pattern, such as {x, y} , there is one parameter node representing the entire parameter, and separate PropRead nodes for the individual property patterns ( x and y ).
Import path
Direct supertypes, indirect supertypes, known direct subtypes.
- ClientRequestLoginCallback
- JQueryPluginOptions
- RouteHandlerParameter
Inherited predicates

IMAGES
VIDEO
COMMENTS
1 Answer Sorted by: 6 This is a common ESLint issue that appears frequently on old codebase. You have modified the result variable which was passed as parameter. This behavior is prohibited by the rule. To resolve it, copy the argument to a temporary variable and work on it instead:
Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object when not in strict mode (see When Not To Use It below). Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.
i have that lint error: Assignment to property of function parameter 'item' What is the correct way to remove this error? const resp = await getData(payload) resp.forEach((item) => { item[...
162 I have a method which's main purpose is to set a property on a DOM object function (el) { el.expando = {}; } I use AirBnB's code style which makes ESLint throw a no-param-reassign error: error Assignment to function parameter 'el' no-param-reassign How can I manipulate a DOM object passed as an argument while conforming AirBnB's code style?
Changing the prototype behind every Vue instance -- and in particular with an enumerable property -- seems like a Bad Thing. - T.J. Crowder Oct 4, 2018 at 15:16
Normally you don't want to assign to a property of the parameter. It mutates the passed parameter which most user don't expect to happen. In your scenario this is most likely not much of a problem, assuming prepareCandidate returns a freshly created object.
With below code, I am getting ESlint error Assignment to property of function parameter 'recurrence' at many places where I // eslint-disable-next-line no-param-reassign disabled the line. I dont want to use disable. How so solve this issue without using disable as legit way? Can anyone help me with this? THanks
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.
Objects passed into function parameters can also be unpacked into variables, which may then be accessed within the function body. As for object assignment, the destructuring syntax allows for the new variable to have the same name or a different name than the original property, and to assign default values for the case when the original object ...
We used the spread syntax (...) to unpack the properties of the function parameter into a new object to which we can assign properties. If you need to unpack an array, use the following syntax instead. index.js const arr = ['bobby', 'hadz', 'com']; const newArr = [...arr];
Options. This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor"."props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor", which is an empty array by default.. props ...
Hello I have a problem in my estlint: Assignment to property of function parameter 'state'. eslintno-param-reassign on this code: state.sideisOpen = action.payload; interface SideBar { sideisOpen: ...
There are two ways to access properties: dot notation and bracket notation. Dot notation In the object.propertyName syntax, the propertyName must be a valid JavaScript identifier which can also be a reserved word. For example, object.$1 is valid, while object.1 is not. js const variable = object.propertyName; object.propertyName = value; js
Assigning to indices Each argument index can also be set or reassigned: js arguments[1] = "new value"; Non-strict functions that only has simple parameters (that is, no rest, default, or destructured parameters) will sync the new value of parameters with the arguments object, and vice versa: js
no-param-reassign as "never reassign parameters" is ok. no-param-reassign as "never mutate parameters" means eslint-config-airbnb enforces immutability paradigm. It makes a profound design choice for us.
node.js - adding an assign function as property to an object in NodeJs - Stack Overflow adding an assign function as property to an object in NodeJs Ask Question Asked 5 years, 8 months ago Modified 5 years, 8 months ago Viewed 2k times 2 for the sake of fun and exploring nodeJS I made an object
8 comments Add a Comment willshowell • 5 yr. ago The point of that eslint rule is to avoid mutating function parameters. In general you probably want to prefer an immutable approach, which is what the rule recommends. However, mutating the request object is exactly how express middleware is supposed to be done.
you eslint is configured to not allow re-assignment of parameters, i.e if a function takes 2 arguments (a, b), then you cant re-assign these 2 variables in the function body. disable the eslint rule (in your .eslintrc or just for the function) create new variables to avoid re-assigning to a and b (see below): sortingalgo = (a, b) => { // we ...
For example, x is a parameter of function f(x) {}. ... Holds if there is an assignment to property propName on this node, and the right hand side of the assignment is rhs. from SourceNode hasUnderlyingType Holds if this node is annotated with the given named type, or is declared as a subtype thereof, or is a union or intersection containing ...