Skip to content

Latest commit

 

History

History
51 lines (43 loc) · 1.63 KB

Naming_Js.md

File metadata and controls

51 lines (43 loc) · 1.63 KB

Naming Conventions - JavaScript

Pascal Case Camel Case Snake Case Lower Case Caps Case
LazyDogBrownFox lazyDogBrownFox lazy_dog_brown_fox lazydogbrownfox LAZYDOGBROWNFOX

Files and Directories

  • lower case with underscorees for readability.
myscript.js
my_other_script.js

Variables, Parameters, and Functions

  • Camel case: Generally.
    • Rarely you will find a leading underscore with variable/function name. It is intended to be used as private though not enforced in JavaScript.
  • Upper case: If global variables or constants. May have underscores between words for readability.
class SoftwareDeveloper {
  constructor(firstName, lastName) {
    this.myFirstName = firstName;
    this.myLastName = lastName;
    this.name = _getName(firstName, lastName);
  }
 
  _getName(firstName, lastName) {
    return `${firstName} ${lastName}`;
  }
}
var dev = new SoftwareDeveloper("King", "Tchalla");
console.log(dev.name); //Good
console.log(dev._getName("King", "Tchalla")); // Bad

const THIS_IS_PI = 3.14;
function doSomething(arg){}

Classes

  • Pascal Case: Names of classes and enumerations
class MyClass {}
namespace MyNamespace {}
public enum MyEnum {}
public interface IMyInterface {}

Reference

For more standards and links refer to Coding Standards Lookup page.

Guidelines

To contribute refer to the Contributing and License pages.