Difference between Function Declaration(or Function Statement) and Function Expression in Javascript?
You might be working for a very long time in javascript but sometimes we don't understand the jargons associated with it. So here I will be demystifying what these jargons mean and what is the difference associated with it.
So basically function declaration tells about the function name, return type and parameters. Example with a code snippet:-
A function expression can be defined as a function stored in a variable. Example:-
So now the question will be what is the difference between these 2 when you call it.
And the answer lies in Hoisting.
So if you call these 2 functions before declaring them function expression always throws an error because function expression has been attached with a variable and when the global execution context is created at that time value of the variable will be undefined for the very first time so that the reason why it will give you an error if you are calling the function before.
Let me know in the comments if you face any issues. Till then Happy Coding.