28.4. Functions in TypeScript

PHOTO EMBED

Wed Aug 31 2022 20:53:42 GMT+0000 (Coordinated Universal Time)

Saved by @cruz #javascript

     function myFunction(a: number, b?:number): number {
             if (typeof b !== 'undefined'){
                     return a+b+5;
                  } else {
                          return a+5;
                  }
          }

console.log(myFunction(1,2));
console.log(myFunction(1));
console.log(myFunction(3,5));
console.log(myFunction(3));
8
6
13
8
content_copyCOPY

https://education.launchcode.org/intro-to-professional-web-dev/chapters/typescript/functions.html