What is the difference between these two functions/approaches?
function, javascript
Solution
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
Problem
I use only jQuery for writing JavaScript code. One thing that confuses me is these two approaches of writing functions, First approach ``` vote = function (action,feedbackId,responseDiv) { alert('hi'); return feedbackId; } ``` Second approach ``` function vote(action, feedbackId,responseDiv) { alert('hi'); return feedbackId; } ``` What is the difference between the two and why should one use the first approach or the second approach?