]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-func-assign.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-func-assign.md
CommitLineData
eb39fafa
DC
1# disallow reassigning `function` declarations (no-func-assign)
2
3JavaScript 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.
4
5```js
6function foo() {}
7foo = bar;
8```
9
10## Rule Details
11
12This rule disallows reassigning `function` declarations.
13
14Examples of **incorrect** code for this rule:
15
16```js
17/*eslint no-func-assign: "error"*/
18
19function foo() {}
20foo = bar;
21
22function foo() {
23 foo = bar;
24}
6f036462
TL
25
26var a = function hello() {
27 hello = 123;
28};
eb39fafa
DC
29```
30
31Examples of **incorrect** code for this rule, unlike the corresponding rule in JSHint:
32
33```js
34/*eslint no-func-assign: "error"*/
35
36foo = bar;
37function foo() {}
38```
39
40Examples of **correct** code for this rule:
41
42```js
43/*eslint no-func-assign: "error"*/
44
45var foo = function () {}
46foo = bar;
47
48function foo(foo) { // `foo` is shadowed.
49 foo = bar;
50}
51
52function foo() {
53 var foo = bar; // `foo` is shadowed.
54}
55```