Using 'return' instead of 'else' in JavaScript

后端 未结 13 1743
無奈伤痛
無奈伤痛 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条回答
  •  半阙折子戏
    2020-12-01 14:47

    There won't be any difference in performance I would recommend the second example for maintainability. In general it's good practice to have one and only one possible exit point for a routine. It aids debugging and comprehension.

提交回复
热议问题