For example, there is the usual function declaration:

var someFunction = function() { ... }; 

And the functional expression:

 function someFunction() { ... } 

What is the fundamental difference?

    1 answer 1

    The difference is that the usual function declaration is created by the interpreter before the code starts.

    Example of a Declaration Function :

     someFunction("Hello world!"); function someFunction(text) { alert(text); } 

    As you can see from the example, the function declaration is after its call and the code works correctly.

    Example of Function Expression (functional expression):

    The functional expression is created by the interpreter during the execution of the code, that is, synchronously, from line to line. And in this case, the function call before its initialization will lead to an error, because the function has not yet been created, and you already call it.

     someFunction("Hello world!"); var someFunction = function(text) { alert(text); } 

    use strict

    One more thing, if you use the use strict directive, then a regular function declaration will not allow you to call a function outside the body of the block in which it is initialized, for example, in a condition.

     'use strict' if (1 > 0) { function someFunction(text) { alert(text); } } someFunction("Hello world!"); 

    The functional expression will work in this case if the variable is initialized in the body of the block or 'above' in which it will be used.

     'use strict' let someFunction; if (1 > 0) { someFunction = function(text) { alert(text); } } someFunction("Hello world!");