Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Capturing Visitor Input

When do you use camelCase and when do you use under_score?

Is camel case or under scores only used for functions and variables? What determines when someone would chose to use one over the other.

Many programmers follow AirBNB naming conventions. Here is a link to their page about variable naming conventions: https://github.com/airbnb/javascript#variables

Use camelCase when naming objects, functions, and instances.

Use PascalCase only when naming constructors or classes.

1 Answer

Steven Parker
Steven Parker
231,269 Points

The most common convention is to use camelCase (starting with a lower-case character) for both variable and function names, and PascalCase (starting with a capital letter) for class names.

Another, but slightly less universal convention, is to name constants using ALL_CAPS with underscores.

Private variable names are sometimes started with an underscore, but are otherwise camelCase.

Lower-case names with underscore word separators (also known as snake_case) is popular in some other languages, but not a typical convention in JavaScript.