SHARE
TWEET

nested function calls

a guest Mar 26th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1)
  2. function checkBalance(balance, withdrawAmount){
  3.     if (balance >= withdrawAmount){
  4.         return true;
  5.     }
  6.  
  7.     return false;
  8. }
  9.  
  10. function withdraw(withdrawAmount){
  11.     return withdrawAmount;
  12. }
  13.  
  14.  
  15. const run () =>{
  16.     if(this.checkBalance(balance, withdrawAmount)){
  17.         this.withdraw(withdrawAmount);
  18.     }else{
  19.         alert("insufficient funds");
  20.     }
  21. }
  22. 2)
  23. function checkBalance(balance, withdrawAmount){
  24.     if (balance >= withdrawAmount){
  25.         this.withDraw(withdrawAmount)
  26.     }else{
  27.         alert("insufficient funds");
  28.     }
  29. }
  30.  
  31. function withDraw(withdrawAmount){
  32.     return withdrawAmount;
  33. }
  34.  
  35.  
  36. const run () =>{
  37.     this.checkBalance(balance, withdrawAmount)
  38. }
  39. I personally feel like 1) is better, because nested calls will add complexity to the logic, but what do you guys think?
  40. I am more interested in what would be the best method, the code is just a simple example
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top