π Prefer default parameters over reassignment.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π‘ This rule is manually fixable by editor suggestions.
Instead of reassigning a function parameter, default parameters should be used. The foo = foo || 123 statement evaluates to 123 when foo is falsy, possibly leading to confusing behavior, whereas default parameters only apply when passed an undefined value. This rule only reports reassignments to literal values.
You should disable this rule if you want your functions to deal with null and other falsy values the same way as undefined. Default parameters are exclusively applied when undefined is received.. However, we recommend moving away from null.
// β
function abc(foo) {
foo = foo || 'bar';
}
// β
function abc(foo = 'bar') {}// β
function abc(foo) {
const bar = foo || 'bar';
}
// β
function abc(bar = 'bar') {}// β
function abc(foo) {
foo = foo || bar();
}