According to hoisting definition:
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution
Why do function declarations get hoisted and function expressions don't?
According to hoisting definition:
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution
Why do function declarations get hoisted and function expressions don't?
Copyright © 2021 Jogjafile Inc.
As per MDN,
As you see, in a function expression, actual function is a value assigned to a named variable. So this named variable is hoisted. Even if you have a named function assigned, it still will not be hoisted as it is not a declaration and will be created later.
Sample: