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:
Initially-capped mixed-case, such as
Date
orFoo
, is pretty much reserved for constructor functions.ALL_CAPS
is typically used only for things that are treated like constants.Everything else seems to start with lower case, and be either
camelCase
orunderscore_separated
. No clear-cut consensus on that, although I thinkcamelCase
has an edge, probably because JavaScript itself uses it (toLowerCase
, etc.).