In JavaScript I've discovered that a function can be declared after it is called but only if it is declared as a function not as a variable.
This works:
alerter('this is an alert');
function alerter(text) {
alert(text);
}
But this doesn't
alerter('this is an alert');
var alerter = function(text) {
alert(text);
}
Can someone explain to me why these are treated differently and maybe give a brief explanation of how JavaScript compiles.