- Series contents
- Function declaration and Function expression
- Difference between Function declaration and Function expression
- Function expression and function declaration
Using function declaration and using function expression.
Function declaration and Function expression
The syntax for function declaration is
and the syntax for function expression is
Both syntax generates similar output. Then why both exists?
Difference between Function declaration and Function expression
Although both statements shows similar output, they’ve a key difference.
So a Function declaration can be called before writing it into the code.
It won’t throw any error.
But in case of Function expression it created when script execute and reaches to it’s line. After that it is available in the code. So like Function declaration if it is called earliar in the code, we will see an error message-
So what’s the benefit?