|
|
|
|
|
by Kiro
4862 days ago
|
|
The answer to "Why are there so many different ways to declare a function? What are the differences?" doesn't really answer the question. No error: <script>
myFunction();
function myFunction() {};
</script>
Error: <script>
myFunction();
var myFunction = function() {};
</script>
A correct answer should explain why this happens in order to understand what the difference really is about. |
|
In the second, the var myFunction gets hoisted to the top but not the function definition, which is why calling it produces an error. In the first, the whole function gets hoisted to the top.