Member Login:


JavaScript Style Guide: Naming Convention

Document Reference: TN200908008 - Rev: 4.17 - Last Update: 04-10-2011 12:01 GMT - Downloaded: 27-May-2019 14:01 GMT

The goal of this JavaScript naming convention is to reduce the effort needed to read and understand code and variable scope by applying a consistent naming standard.

Good Practice

Available Characters

Identifier names can contain both letters, numbers and underscores. However, names cannot start with a number. Underscores and dollor signs (e.g. Angular) can be used in some cases. See below for more details.

Never use hyphens in variable names as these could be interpreted as subtraction attempts. Remember that names are case sensitive.

Avoid Characters I, l Or O

The single characters I (aka capital letter of i), l (aka lowercase of L) or O (aka capital letter of o) should not be used as variable names. These variable names could easily be mistaken as numerals 1 (one) and 0 (zero).

Meaningful Names

Within reason and to help clearly document what a name is used for, choose meaningful and descriptive names that implies the intent and meaning of the code.

Acronyms

Do not capitalize all the letters of acronyms. For mixedCase (CamelCase with an initial lowercase character) use httpError instead of HTTPError and for UpperCamelCase (CamelCase with an initial uppercase character) use HttpError instead of HTTPError.

Variables

Use mixedCase (CamelCase with an initial lowercase character) for naming variables, e.g. mixedCase.

MCR Style Configuration Example
mixedCase

Constants

Use UPPER_CASE_WITH_UNDERSCORES for naming constants, e.g. CONSTANT_NAME.

MCR Style Configuration Example
CONSTANT_NAME

Functions

Use mixedCase (CamelCase with an initial lowercase character) for naming functions, e.g. functionName().

MCR Style Configuration Example
functionName()

Constructors

Use UpperCamelCase (CapWords) for naming constructors, e.g. ConstructorName().

MCR Style Configuration Example
ConstructorName()

Classes

Use UpperCamelCase (CapWords) for naming classes, e.g. ClassName.

MCR Style Configuration Example
ClassName

Reserved Keywords

Listed keywords (aka identifiers) below are reserved by JavaScript and must not be used when choosing names:

  • break
  • case
  • catch
  • const
  • continue
  • debugger
  • default
  • delete
  • do
  • else
  • finally
  • for
  • function
  • if
  • in
  • instanceof
  • let
  • new
  • return
  • switch
  • this
  • throw
  • try
  • typeof
  • var
  • void
  • while
  • with

This website uses cookies to give you the best experience on our website, to personalise content and to analyse our website traffic. Some cookies may have been set already. To find out more about our use of cookies you can visit our Privacy Statement. By browsing this website, you agree to our use of cookies.

Hide this message