How to make the function exit in advance instead of nested conditional branches by JavaScript
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.