Using 'return' instead of 'else' in JavaScript

后端 未结 13 1747
無奈伤痛
無奈伤痛 2020-12-01 14:09

I am working on a project which requires some pretty intricate JavaScript processing. This includes a lot of nested if-elses in quite a few places.

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 14:49

    In many languages, is a common practice to invert if statements to reduce nesting or use preconditions.

    And having less nesting in your code improves code readability and maintainability.

提交回复
热议问题