JavaScript · Naming convnetions · Programming

JavaScript Variable Naming Convention

The following are the rules for naming JavaScript variables.

  1. Names must start with an alphabet or underscore but never with a numeral. It must be composed of letters, numbers and underscores only. Names must not contain spaces.Valid names:
    var name = ‘foo’;
    var _code = 123;
    String str2 = new String(‘Hello’);
    var count_2 = 123; 

    Invalid names:
    var 2bar = 'er';//must not start with a numeral
    var ff+bar = 'err';//no mathematical operators
    var bad-yuio = 'err';//no special characters
    var very bad name = 1;//no spaces

  2. JavaScript keywords should not be used as variable names. For example all of the following are illegal:

    var window = 'err';
    var document = 'err'; 


  3. JavaScript variable names are case-sensitive. So all of the following names are distinct variables:

    var byteCode = '1';
    var ByteCode = '1';
    var bytecode = '1'

Leave a Reply

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

You are commenting using your 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