function = action
해야 할 일을 적어놓고 (definition)
그 일을 수행 (call)
함수 선언식
// The simplest function
function sayHello() {
alert('hello');
}
sayHello();
함수의 입력/출력
function sayMyName(name: string) {
alert('name: ' + name);
console.log('function sayMyName was called');
}
sayMyName('a student studying typescript');
function addTwoNumber(a: number, b: number) {
return a + b;
}
addTwoNumber(2, 3); // Nothing happens
alert(addTwoNumber(2, 3));
변수 <- 함수
var f1 = function(i: number): number { return i * i; }
var f2 = function(i: number) { return i * i; }
var f3 = (i: number): number => { return i * i; }
var f4 = (i: number) => { return i * i; }
var f5 = (i: number) => i * i;
'Web > Typescript' 카테고리의 다른 글
반복문 (Loops) (0) | 2017.03.21 |
---|---|
조건문 (conditions) (0) | 2017.03.21 |
Variables concept (0) | 2017.03.20 |
Intro to Typescript (0) | 2017.03.20 |
ts vs js (0) | 2017.03.20 |