1 # Disallow Reassignment of Function Parameters (no-param-reassign)
3 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.
5 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.
9 This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.
11 Examples of **incorrect** code for this rule:
14 /*eslint no-param-reassign: "error"*/
33 Examples of **correct** code for this rule:
36 /*eslint no-param-reassign: "error"*/
45 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.
49 Examples of **correct** code for the default `{ "props": false }` option:
52 /*eslint no-param-reassign: ["error", { "props": false }]*/
67 for (bar.aaa in baz) {}
71 for (bar.aaa of baz) {}
75 Examples of **incorrect** code for the `{ "props": true }` option:
78 /*eslint no-param-reassign: ["error", { "props": true }]*/
93 for (bar.aaa in baz) {}
97 for (bar.aaa of baz) {}
101 Examples of **correct** code for the `{ "props": true }` option with `"ignorePropertyModificationsFor"` set:
104 /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/
119 for (bar.aaa in baz) {}
123 for (bar.aaa of baz) {}
127 Examples of **correct** code for the `{ "props": true }` option with `"ignorePropertyModificationsForRegex"` set:
130 /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsForRegex": ["^bar"] }]*/
132 function foo(barVar) {
133 barVar.prop = "value";
136 function foo(barrito) {
144 function foo(barBaz) {
145 for (barBaz.aaa in baz) {}
148 function foo(barBaz) {
149 for (barBaz.aaa of baz) {}
154 ## When Not To Use It
156 If you want to allow assignment to function parameters, then you can safely disable this rule.
160 * [JavaScript: Don’t Reassign Your Function Arguments](https://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/)