General Naming Conventions for JavaScript

Question
Generally speaking, what’s the recommended naming style for JavaScript?

Answer
It’s camelCase. ECMAScript, which is JavaScript’s core, uses the camelCase convention. Thus, when naming variables and functions, begin them with a lowercase letter and make each subsequent word begin with an uppercase letter. See the Examples section.

Comments
Many notable JavaScript style guides, such as the ones by Google, SproutCore, and Dojo, specify the use of camelCase. Also, don’t use Hungarian notation. It’s no longer recommended.

Examples

var aBasicVariable;
let aScopedVariable;
const aConstant;

function doSomething() {
    ...
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s