const print = function () { //anonymous function
console.log('print');
};
print();
=print
const printAgain = print;
printAgain();
=print
const sumAgain = sum;
console.log(sumAgain(1,3))
=4
function randamQuiz(answer, printYes, printNo) {
if(answer === 'love you') {
printYes();
} else {
printNo();
}
}
anonymous function: 이름이 없는 function
const printYes = function (){
console.log('yes!');
};
named function
const printNo = function print() {
console.log('no!')
print();
};
randamQuiz('wrong', printYes, printNo);
randamQuiz('love you', printYes, printNo);
Arrow function
const simplePrint = function() {
console.log('simplePrint!');
};
const simplePrint = () => console.log('simplePrint!');
const add = (a, b) => a + b;
const simpleMultiply = (a, b) => {
//do something more
return a * b;
};
IIFE: Immediately Invoked Function Expression
(function hello() {
console.log('IIFE');
})();
=IIFE가 출력된다.
출처: 드림코딩 자바스크립트 기초 강의 (ES5+)