Skip to content

Use default parameters instead of thernary operator #20

@fumegalli

Description

@fumegalli

Hi,

While using this repository as an example to build my app, I saw an opportunity to contribute cleaning the code.
Default parameters are often cleaner than shorting circuiting (or thernary operator, in this case).

Be aware that if you use default parameters, your function will only provide default values for undefined arguments. Other "falsy" values such as '', "", false, null, 0, and NaN, will not be replaced by a default value.

So, if this is a problem in this case, please, let me know.

Bad:

public clientError (message?: string) {
return BaseController.jsonResponse(this.res, 400, message ? message : 'Unauthorized');
}

Good:

public clientError (message = 'Unauthorized') {
    return BaseController.jsonResponse(this.res, 400, message);
}

Reference:
https://github.com/ryanmcdermott/clean-code-javascript#use-default-parameters-instead-of-short-circuiting-or-conditionals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions