Is it possible to make youth return/stop executing from within box? Directly, not something like:
function youth(){
  var check = true;
  function box(){
    //code
    check = false;
  }
  //code
  while(check){
    //code;
  }
  return false;    
}
(where there is a check variable which box changes)
No, you cannot, unless you throw an exception from the inner function (but that doesn't really count as "returning," and it's not really a good design pattern anyway).
It does not make sense to allow a function to make its caller return a value, since the calling function might not even be declared in the same context -- perhaps it is some other function that accepts a function argument, and that passed-in function shouldn't be able to modify the called function's behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With