Type Script-関数
1461 ワード
//js
function add1(x,y){
return x+y
}
const add2 = function(x,y){
return x+y
}
//TS ,
function add3(x:number,y:number):number{
return x+y
}
const add4 = function(x:number,y:number):number{
return x+y
]
//
//const add5: = function(x:number,y:number):number{return x+y}
// =(x:number,y:number)=>number
const add5: (x:number,y:number)=>number =function(x:number,y:number):number{
return x+y
}
: : =
: ?:
function getFullName(firstName:string=' ',lastName?:string):string{
if(lastName){
return firstName + '_' + lastName
}else{
return firstName
}
}
console.log(getFullName()) //
console.log(getFullName(' ')) //
console.log(getFullName(' ',' ')) // _
...args:string[] // string
function showMsg(str:string,...args:string[]){ //args , , args
consoel.log(str) //a
console.log(args) //['b','c','d','e']
}
showMsg('a','b','c','d','e')