This kind of behavior can be a cause for error if you don’t understand it, because functions may be available when you don’t expect them to be. If you don’t want this effect, assign your functions to variables. Now since we’re on functions, let’s discussing scoping rules:
As you can see var drips out of the block scope and is available throughout the entire function; const and let do not. Furthermore, they also throw errors if used incorrectly. In most cases, let and const are preferred over var; const and let can accomplish more consistent rules when compared to var. Well, since we’re on variables, let’s discuss pass by value & cloning.
Pass By Value