Skip to content

username length check compares boolean to zero #1638

@ElectricNroff

Description

@ElectricNroff

if (!body?.username || typeof body?.username !== 'string' || !body?.username.length > 0) {
return res.status(400).json({ message: 'Parameters were invalid', details: [{ param: 'username', msg: 'Parameter must be a non empty string' }] })
}

body?.username already checks for a nonzero length because "" is falsy.

!body?.username.length > 0 means to convert a zero length to true and convert any other length to false, and then compare that boolean to zero. Because this code is reached only when the length is nonzero,

|| !body?.username.length > 0

is always equivalent to:

|| false

and can be omitted.

Metadata

Metadata

Assignees

Labels

Easy1-5 Hours

Type

No type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions