Ad
Functions
Control Flow
Basic Language Features
Fundamentals

Return early from a function with some data if condition is met withing child function, otherwise return 'no return'.

The test inputs 'toReturn' and 'returnWhat' MUST be passed to child funciton and SHOULD NOT be referenced in parent. No mutations of test inputs should occur.

const returnFromChild=(toReturn, returnWhat)=>{
  
  const child=(toRet, retWhat)=>{
    if(toRet){
      return retWhat
    }
  }
  
  const retThis = child(toReturn,returnWhat);
  if(retThis!=undefined){
    return retThis
  }
  
  return 'no return'
}