JS.BASE.DEFAULT.PARAM.LAST

Enforce default parameters to be last

Putting default parameter at last allows function calls to omit optional tail arguments.

Copy
// Correct: optional argument can be omitted
function createUser(id, isAdmin = false) {}
createUser("tabby")

// Incorrect: optional argument can **not** be omitted
function createUser(isAdmin = false, id) {}
createUser(undefined, "tabby")

Rule Details

This rule enforces default parameters to be the last of parameters.

Examples of incorrect code for this rule:

Copy
/* eslint default-param-last: ["error"] */

function f(a = 0, b) {}

function f(a, b = 0, c) {}

Examples of correct code for this rule:

Copy
/* eslint default-param-last: ["error"] */

function f(a, b = 0) {}

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/