How to use nested functions in TypeScript

1 Answer

0 votes
function foo() {
    console.log("foo()");
      
    function in_func() { // accessible only within foo()
        return 28;
    }
      
    console.log("before return");
      
    return in_func();
}
    
console.log(foo());
   
   
   
   
/*
run:
    
"foo()" 
"before return" 
28 
    
*/

 



answered May 30, 2022 by avibootz
edited May 31, 2022 by avibootz
...