I am a software developer that loves to research, learn and unlearn to solve human and business problems. I write PHP(Laravel), JavaScript(React), I contributed to Firefox Debugger and tutor @udemy.
I like this question because it feels like what I should have explained in the write-up.
Function expressions are not hoisted even when we use them with "var";
Thanks for raising the question.
The practical differences could be:
We can't define or declare a regular functions in a conditional statement like if it is necessary to do so (but it is rarely necessary if not impossible), in that case we have to use function expression.
(function(){'use strict';if(true){functiongoing(){return'yes';}}else{functionnotGoing(){return'no';}}console.log(typeofgoing==='undefined');// => trueconsole.log(going());// Throws "ReferenceError: going is not defined"})();
We will use function expression to make it work.
Note: Declaring a function in a conditional statement is not recommended or should be avoided.
2 . It is easy to pass a function expression around so it is used to create modules without worrying about polluting the global scope before the introduction of import and export.
I like this question because it feels like what I should have explained in the write-up.
Function expressions are not hoisted even when we use them with "var";
Thanks for raising the question.
The practical differences could be:
We will use function expression to make it work.
Note: Declaring a function in a conditional statement is not recommended or should be avoided.
2 . It is easy to pass a function expression around so it is used to create modules without worrying about polluting the global scope before the introduction of import and export.
Thanks very much! Very nice text (: