JavaScript for WordPress › Forums › Vanilla JavaScript › Function as variable › Reply To: Function as variable
Good question.
I actually went back and forth on what to call the “preferred” method for declaring functions since you will see a lot of functions in JS that are not assigned as variables.
The added benefit of assigning functions as variables is that you can later change the function assigned to the variable, which is not too common really. However, one extra thing you can do is assign the function to a different variable name if you needed to refer the function as something else in another context.
Although I do call this preferred here, I have talked to some pros since making the video who don’t feel its usually necessary to take this extra step.
Hope this unpacks the topic a bit more for you?