코드가 계산(Evaluation) 되어 값을 만드는 것
const val = 10;
const func = (val) => {
return 'hello?'
}
func(val);
const add = a => a + 5;
console.log(add); // a => a + 5
console.log(add(1)); // 6
const func1 = () => () => 1;
console.log(func1()); // () => 1
const func2 = func1();
console.log(func2); // () => 1
console.log(func2()); // 1
함수를 값으로 다루는 함수
const func1 = func2 => func2(1);
const add = a => a + 1;
console.log(func1(add)); // 2
console.log(func1(a => a + 2)); // 3
const increase = (func, n) => {
let i = -1;
while (++i < n) func(i);
}
increase(console.log, 3); // 0 1 2
increase(a => console.log(a+1), 3) // 1 2 3
const add1 = a => b => a + b;
const add2 = add1(10);
console.log(add2); // b => a(10) + b (a를 기억하고 있음)
console.log(add2(2)); // 12
console.log(add2(3)); // 13
클로저(closure)는 내부함수가 외부함수의 맥락(context)에 접근할 수 있는 것