Difference between Function Declaration and Function Expression
Function Declaration | Function Expression |
---|---|
A function declaration must have a function name. | A function expression is similar to a function declaration without the function name. |
Function declaration does not require a variable assignment. | Function expressions can be stored in a variable assignment. |
These are executed before any other code. | Function expressions load and execute only when the program interpreter reaches the line of code. |
The function in function declaration can be accessed before and after the function definition. | The function in function expression can be accessed only after the function definition. |
Function declarations are hoisted | Function expressions are not hoisted |
Syntax: function w3wiki(paramA, paramB) { // Set of statements } | Syntax: var w3wiki= function(paramA, paramB) { // Set of statements } |
Difference between âfunction declarationâ and âfunction expressionâ in JavaScript
Functions in JavaScript allow us to carry out some set of actions, important decisions, or calculations and even make our website more interactive. In this article, we will learn the difference between âfunction declarationâ and âfunction expressionâ. The similarity is both use the keyword function and the most prominent difference is that the function declaration has a function name while the latter doesnât have one.
Contact Us