Function declaration은 function을 declare하기 전에 call할 수 있음
Expression은 그렇게 안됨 🙅♀️
Expression은 declare하기 전에 해당 function을 call하면 에러 뜸
e.g. Uncaught ReferenceError: Cannot access 'OOO' before initialization
// Function declaration
function calcAge1(birthYear) {
return 2037 - birthYear;
}
const age1 = calcAge1(1991);
// Function expression
// Expression produces value
// Functions are not type, but value storing a variable
const calcAge2 = function (birthYear) {
return 2037 - birthYear;
}
const age2 = calcAge2(1991);
console.log(age1, age2);
// prints 46 46
'Programming > JavaScript' 카테고리의 다른 글
Functions Calling Other Functions (0) | 2022.09.03 |
---|---|
Arrow Functions (0) | 2022.09.03 |
Activating Strict Mode (0) | 2022.09.02 |
Functions (0) | 2022.09.02 |
Coding Challenge #4 - tip calculator using ternary operator (0) | 2022.08.30 |