Skip to content
Advertisement

JavaScript function parameter naming conventions [closed]

Is it common to use the accepted parameter naming conventions for a JavaScript function? For example:

function MyFunction(nParam1, tParam2, oParam3) {..}

where nParam1 is a number, tParam2 is text, and oParam3 is an object

It makes sense to do this, but there is a lot of code I still see that does not use this naming convention.

Advertisement

Answer

Is it common to use the accepted parameter naming conventions for a JavaScript function?

I don’t know what you mean by “…the accepted parameter naming conventions…” (I’ve seen at least half a dozen argument naming conventions in various languages and environments, none “accepted” universally)…

…But the answer is no, there is no broadly-used naming convention for function arguments in JavaScript — unless you consider just using plain names (e.g., without any Hungarian-esque prefixes and such) a convention. Plain names is the overwhelmingly most common thing I see. Specifically, plain names that start with a lower-case letter. Once you get past that, there’s more variety. camelCase is common, but so is snake_case.

The closest things I see in the wild in terms of conventions are:

  1. Initially-capped mixed-case, such as Date or Foo, is pretty much reserved for constructor functions.

  2. ALL_CAPS is typically used only for things that are treated like constants.

  3. Everything else seems to start with lower case, and be either camelCase or underscore_separated. No clear-cut consensus on that, although I think camelCase has an edge, probably because JavaScript itself uses it (toLowerCase, etc.).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement