General
A function expression is only defined when its line is reached. So they're not available until the browser reaches them.
sayHello() // sayHello is not a function
var sayHello = function() {
return 'say hello';
}
A function declaration is available throughout a function's scope. They are loaded before the browser executes any code.
sayHello(); // 'say hello'
function sayHello() {
return 'say hello';
}
This means you cannot conditionally declare a function using a function declaration.
sayHello(); // 'say hello';
if (condition) {
function sayHello() {
return 'say hello';
}
}
References
https://developer.mozilla.org/en-US/docs/web/JavaScript/Reference/Operators/function