]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/default-param-last.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / default-param-last.md
1 ---
2 title: default-param-last
3 layout: doc
4 rule_type: suggestion
5 ---
6
7 Putting default parameter at last allows function calls to omit optional tail arguments.
8
9 ```js
10 // Correct: optional argument can be omitted
11 function createUser(id, isAdmin = false) {}
12 createUser("tabby")
13
14 // Incorrect: optional argument can **not** be omitted
15 function createUser(isAdmin = false, id) {}
16 createUser(undefined, "tabby")
17 ```
18
19 ## Rule Details
20
21 This rule enforces default parameters to be the last of parameters.
22
23 Examples of **incorrect** code for this rule:
24
25 ::: incorrect
26
27 ```js
28 /* eslint default-param-last: ["error"] */
29
30 function f(a = 0, b) {}
31
32 function f(a, b = 0, c) {}
33 ```
34
35 :::
36
37 Examples of **correct** code for this rule:
38
39 ::: correct
40
41 ```js
42 /* eslint default-param-last: ["error"] */
43
44 function f(a, b = 0) {}
45 ```
46
47 :::