퀴즈3

  1. Will this code compile?
function sendRequest(data: string, cb: (response: any) => void) { // ... sending a request with "data" return cb({data: 'Hi there!'}); } sendRequest('Send this!', (response) => { console.log(response); return true; });
답 : YES
That's correct. As you learned, callback functions can return something, even if the argument on which they're passed does NOT expect a returned value.
콜백함수는 void여서 return 값은 언제나 null과 undefined 이다.
따라서 함수 안에서 return은 아무 영향을 주지 않는다.
 
  1. What's the idea behind a "function type"?
답: Function types define the parameters and return type of function
함수타입은 파라미터타입과 반환값의 타입을 정한다.
 
  1. Which code snippet is better (i.e. which code should you write)?
function sayHi(): void { // ... } function sayHi(): undefined { // ... }
답 : 1) because it doesn't force you to return anything if you don't want to return somgthing