In JavaScript, all functions are objects (of type Function
). When you create a function, you're creating a new Function
object and assigning it to a variable. In your case, you saved the function to the variable, displayName
. If you want to return it, you put return [variableName]
, just like with any other object.
When you put ()
after the name of a variable storing a Function
object, you are invoking the function. It's much like doing displayName.call(this)
. It's not exactly the same, as there are some important differences, but it's the same concept.
So if you put return displayName()
, rather than returning a reference to the function itself, it would invoke the function and return whatever the function returned.