Skip to content

Files

Latest commit

 

History

History
27 lines (19 loc) · 447 Bytes

no-lonely-if.md

File metadata and controls

27 lines (19 loc) · 447 Bytes

Pattern: Nested solitary if statement

Issue: -

Description

Having an if statement as the only statement inside another if block without else reduces readability. These conditions should be combined using logical operators.

Examples

Example of incorrect code:

if (foo) {
  if (bar) {
  }
}

if (foo) if (bar) baz();

Example of correct code:

if (foo && bar) {
}

if (foo && bar) baz();