⊗jsPmFTFVSN 228 of 504 menu

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.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline