What is the difference between these two functions/approaches?

前端 未结 4 1526
南旧
南旧 2020-12-06 07:10

I use only jQuery for writing JavaScript code. One thing that confuses me is these two approaches of writing functions,

First approach



        
4条回答
  •  渐次进展
    2020-12-06 07:40

    The first is a function expression assigned to the vote variable, the second is a function declaration.

    The main difference is that function statements are evaluated at parse time, they are available before its declaration at runtime.

    See also:

    • Named function expressions demystified (article)
    • Explain JavaScript’s encapsulated anonymous function syntax

提交回复
热议问题