함수 선언식 - Function Declarations
함수 표현식 - Function Expressions

 

// <function>
//this is function declaration. 
//function hoisting is only work for function declaration.
calculateAge(1965);//<-hoisting: we can call the function before even we declaire the function.

function calculateAge(year){
    console.log(2016-year);
}

//this is function expretion
//retirement(1956);<- you can not bring out the result here through function expretions.
var retirement = function(year){
    console.log(65-(2016-year));
}

retirement(1956);

 

// <variable>
console.log(age);// printed: undefined // variable that doesn't have values yet It always has data type 'undefined'.
var age= 23;//글로벌변수

function foo(){
   // console.log(age); //undefined
    var age =65;//지역변수
    console.log(age);
}

foo();//65 
console.log(age);//23
// each of them get their own variable obj. so printed results are diffrent.

 

'javascript' 카테고리의 다른 글

JavaScript/ The 'this' keyword  (0) 2020.02.24
JavaScript/ Scoping/ 변수영역  (0) 2020.02.24
JavaScript/ Loops and Iteration  (0) 2020.02.13
JavaScript/ Objects and Methods  (0) 2020.02.13
JavaScript/ Object and Properties  (0) 2020.02.13