// Function declaration function run():string{ return 'run'; // return 123; // error } // Function expression var
run2=function test():number{ return 123; } alert(run2()); // Methods pass on the reference function
getInfo(name:string,age:number):string{ return `${name} ----${age}`; } alert(
getInfo('alice',20)) // Method without return value function run3():void{ console.log('run3') } run3
() // be careful : Optional parameters must be configured to the end of the parameter function getInfo(name:string,age?:number):string{ if(
age) { return `${name} ----${age}`; } else { return `${name} ---- Age confidentiality `; } }
// Default parameters function getInfo(name:string,age:number=20):string{ return `${name} ----
${age}`; } // Three point operator Accept the value from the new parameter // Note the , Cannot pass in a data function sum2(...result:number[
]):number { var sum = 0; for(var i=0;i<result.length;i++) { sum+= result[i]; }
return sum; } alert(sum2(1,2,3,4,8,9)) function sum3(a:number,b:number,...result
:number[]):number { var sum = a+b; for(var i=0;i<result.length;i++) { sum+=
result[i]; } return sum; } // alert(sum3(1,2,3,9)) var arr04:number[] = [3,9,8];
var p2 = sum3(1,2,...arr04) console.log('p2:'+p2) // ts Overload in function getInfo(
name:string):string; function getInfo(age:number):string; function getInfo(str:
any):any { if(typeof str=='string'){ return ' My name is '+str } else { return ' My age is '+str
} }; alert(getInfo(' Zhang San ')); // correct alert(getInfo(20)); // correct type str= string;
// Type alias var username:str = 'laney'; function fun6(name:str):str{ return 'hello '
+name; } alert(fun6(username)) type abc = string | number[]; type num = number;
function fun7(a:abc):num{ return a.length; } alert(fun7([1,2,3]));

Technology
©2019-2020 Toolsou All rights reserved,
Unity Scene loading asynchronously ( Implementation of loading interface )ESP8266/ESP32 System : Optimize system startup time vue Of v-if And v-show The difference between JS How to operate college examination for the self-taught An overview of Marxism Faster RCNN Explanation of series algorithm principle ( note )CSS architecture design NOI2019 travels IAR Installation and use tutorial sort ( one ) bubble sort