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:

// 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:

func(); // error, there is no such function yet! let func = function() { console.log('!'); };

Create a function as a Function Declaration. Check that it will be available above the place of its declaration.

Create a function as a Function Expression. Check that it will not be available above the place of its declaration.

enru