Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make the function exit in advance instead of nested conditional branches by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:35:21 10月04日 Update

This article will explain in detail how JavaScript lets the function exit in advance instead of nested conditional branches. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Let the function exit in advance instead of the nested conditional branch

Change the function to multiple exits and return ahead of time, replacing the nested conditional branch.

Function del (obj) {var ret; if (! obj.isReadOnly) {/ / ability that is not read-only is deleted if (obj.isFolder) {/ / if it is a folder ret = deleteFolder (obj);} else if (obj.isFile) {/ / if it is a file ret = deleteFile (obj);}} return ret;}; function del (obj) {if (obj.isReadOnly) {/ / reverse if expression return } if (obj.isFolder) {return deleteFolder (obj);} if (obj.isFile) {return deleteFile (obj);}}; this is the end of the article on "how to let the function exit in advance instead of nested conditional branches". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Functions branches conditions articles files more good practical content folders articles knowledge expressions Cheng duo export reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Shulou Information Shulou Technology Microsoft