What is the difference between Function declaration and Function expression?

Function declarationFunction expression
Declared as a separate statement within the main JavaScript code Created inside an expression or some other construct
Can be called before the function is definedCreated when the execution point reaches it; can be used only after that
Offers better code readability and better code organizationUsed when there is a need for a conditional declaration of a function
Example:function abc() {    return 5;}Example:var a = function abc() {    return 5;}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *