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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter