Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalization convention for JavaScript objects

People also ask

How do you capitalize something in JavaScript?

The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.

Are JavaScript files capitalized?

File names must be all lowercase and may include underscores ( _ ) or dashes ( - ), but no additional punctuation. Follow the convention that your project uses.

Should JavaScript functions be capitalized?

According to the book "Javascript: the good parts", you should only capitalise the first character of the name of a function when you need to construct the object by "new" keyword.

Is JavaScript camelCase or underscore?

camelCase is used by JavaScript itself, by jQuery, and other JavaScript libraries. Do not start names with a $ sign. It will put you in conflict with many JavaScript library names.


You can follow this Google JavaScript Style Guide

In general, use functionNamesLikeThis, variableNamesLikeThis, ClassNamesLikeThis, EnumNamesLikeThis, methodNamesLikeThis, and SYMBOLIC_CONSTANTS_LIKE_THIS.


The convention is that there is no convention. Do what you want, just be consistent. I suggest follow Java style and ignore whatever convention the library (dojo, Ext, YUI, $, etc) you happen to be using is following.


As recommended by Douglas Crockford:

"Constructor functions that must be used with the new prefix should start with a capital letter. JavaScript issues neither a compile-time warning nor a run-time warning if a required new is omitted. Bad things can happen if new is missing, so the capitalization convention is an important defense."

https://www.crockford.com/code.html