Should files be named something-with-hyphens.js, camelCased.js, or something else?
I didn't find the answer to this question here.
// bad var dogname = 'Droopy'; // bad var dog_name = 'Droopy'; // bad var DOGNAME = 'Droopy'; // bad var DOG_NAME = 'Droopy'; // good var dogName = 'Droopy'; The names of variables should be self-explanatory and describe the stored value.
JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one. JavaScript variable names are case-sensitive.
When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter.
JavaScript files have the file extension .js.
One possible naming convention is to use something similar to the naming scheme jQuery uses. It's not universally adopted but it is pretty common.
product-name.plugin-ver.sion.filetype.js
where the product-name
+ plugin
pair can also represent a namespace and a module. The version
and filetype
are usually optional.
filetype
can be something relative to how the content of the file is. Often seen are:
min
for minified filescustom
for custom built or modified filesExamples:
jquery-1.4.2.min.js
jquery.plugin-0.1.js
myapp.invoice.js
I'm not aware of any particular convention for javascript files as they aren't really unique on the web versus css files or html files or any other type of file like that. There are some "safe" things you can do that make it less likely you will accidentally run into a cross platform issue:
various-scripts.js
, a hyphen is a safe and useful and commonly used separator.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With