Skip to content

Commit aecf2f3

Browse files
committed
🚩: undefined 출력되는 void 함수 예시
1 parent 2be21e5 commit aecf2f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function printResult(num: number): void {
99
printResult(add(1, 2));
1010

1111
let result: Function;
12-
result = add
12+
result = add;
13+
result = printResult; //이렇게 재할당을 할 경우 undefined를 출력한다. 이유는 printResult의 값이 void이기 때문이다.
1314
// result = 0; //값이 재할당 되면서 0으로 값이 출력된다.
1415
console.log(result(1, 2)); //그렇다면 result 변수에 함수 타입을 지정하면 되지 않을까?

0 commit comments

Comments
 (0)