Function and variable same name in JavaScript

It follows from the above that the presence of a variable and a function with the same names can easily lead to a problem.

In the following example, the function func will be overwritten and replaced by the string 'string':

function func() { return '!'; } func = 'string'; // overwrites the variable with function by the string func(); // we get an error, because func is not a function

To prevent this from happening, you should follow the rule common to all programming languages: functions must be verbs, and variables must be nouns.

enru