ESLint v8.x reached end-of-life on 2024-10-05 and is no longer maintained. Upgrade or consider long-term support options
Selecting a version will take you to the chosen version of the ESLint docs.

no-func-assign

Disallow reassigning function declarations

Recommended

The "extends": "eslint:recommended" property in a configuration file enables this rule

JavaScript functions can be written as a FunctionDeclaration function foo() { ... } or as a FunctionExpression var foo = function() { ... };. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.

function foo() {}
foo = bar;

Rule Details

This rule disallows reassigning function declarations.

Examples of incorrect code for this rule:

Open in Playground
/*eslint no-func-assign: "error"*/

function foo() {}
foo = bar;

function baz() {
    baz = bar;
}

var a = function hello() {
  hello = 123;
};

Examples of incorrect code for this rule, unlike the corresponding rule in JSHint:

Open in Playground
/*eslint no-func-assign: "error"*/

foo = bar;
function foo() {}

Examples of correct code for this rule:

Open in Playground
/*eslint no-func-assign: "error"*/

var foo = function () {}
foo = bar;

function baz(baz) { // `baz` is shadowed.
    baz = bar;
}

function qux() {
    var qux = bar;  // `qux` is shadowed.
}

Handled by TypeScript

It is safe to disable this rule when using TypeScript because TypeScript's compiler enforces this check.

Version

This rule was introduced in ESLint v0.0.9.

Resources

Theme Switcher

Selecting a language will take you to the ESLint website in that language.