Difference between declarations
Both ways of declaring a function are equivalent, but there is a significant difference: functions declared as Function Declaration will be available even if they are accessed before they were declared.
See an example:
javascript// Calling a function before it is declared:
func(); // shows '!'
function func() {
console.log('!');
}
And Function Expressions are created at the time of code execution and are not available above. So this code will throw an error:
javascriptfunc(); // error, there is no such function yet!
let func = function() {
console.log('!');
};
Задание 1
Create a function as a Function Declaration. Check that it will be available above the place of its declaration.
Задание 2
Create a function as a Function Expression. Check that it will not be available above the place of its declaration.