In Javascript, I have seen
var QueryStringToHash = function QueryStringToHash (query) {
...
}
What is the reason of writing that instead of just
function QueryStringToHash(query) {
...
}
?
This comes from the answer in The $.param( ) inverse function in JavaScript / jQuery
Declaring a function means that it’s defined when the script block is parsed, while assigning it to a variable is done at runtime:
but:
Assigning a function to a variable can be done conditionally. Example: