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 trialCole Mckeon
Courses Plus Student 641 PointsWhen 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.
1 Answer
Steven Parker
231,275 PointsThe 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.
clickpass
23,992 Pointsclickpass
23,992 PointsMany 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.