Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 564 Bytes

avoid-comparing-multiple-values-with-includes.md

File metadata and controls

19 lines (14 loc) · 564 Bytes

Avoid comparing multiple values with `includes`

Instead of doing:

if (req.method === "POST" || req.method === "PUT" || req.method === "DELETE") {
  console.log("Method allowed");
}

Do:

if (["POST", "PUT", "DELETE"].includes(req.method)) {
  console.log("Method allowed");
}

This will very situational, but when comparing multiple values you can use include to improve legibility. Also make sure that an early return isn't more appropriate first.