learning

함수 생성

눈침침 2011. 3. 25. 08:18
foo; // 'undefined'
foo(); // this raises a TypeError
var foo = function() {};
Due to the fact that var is a declaration, that hoists(=올리다.) the variable name foo before the actual execution of the code starts, foo is already defined when the script gets executed.
JavaScript Garden

즉 다음과 같은 코드로 해석된다는 이야기.

var foo;
foo; // 'undefined'
foo(); // this raises a TypeError
foo = function() {};