JavaScript Naming conventions

Source: Internet
Author: User
Tags arithmetic operators

Source: http://www.codelifter.com/main/tips/tip_020.shtml

The following is the rules for naming JavaScript variables:

1.
A variable name cannot start with a numeral. For instance,3xor2goatsor76trombonesWould all is illegal variable names.

You can, however, has numbers within a JavaScript variable name; For instanceUp2meorGO4itwould both be perfectly valid variable names.

Cannot start with a number


2.
You cannot has a mathematical or logical operator in a variable name. For instance, 2*something or this+that would both be illegal ... because the * and th E + is arithmetic operators. The same holds true for ^,/, \,!, etc.

Cannot contain operator in variable name



3.
You must no punctuation marks of any kind in a JavaScript variable name, other than The underscore; For example ...some:thingorbig#orDo ' toWould all is illegal.

The underscore is the exception, and it can be used at the beginning, within, or at the end of the JavaScript Variab Le names. You can use names like_poundsorsome_thingorGallons_As variable names and they are perfectly legal.

The variable name cannot have punctuation, except for any punctuation marks other than _ underline.

4.
JavaScript names must not contain spaces. Ever.

cannot have spaces in variable names

5.
You cannot use JavaScript keywords (parts of the language, itself) for variable names. ThuswindoworOpenor Locationorstringwould be illegal. Check a JavaScript reference if in doubt as to whether something was or is not part of the language-JavaScript have grown into a fairly fully-fleshed language, so you may get some occasional surprises.

You can, the course, use what is otherwise keywords as parts of variable names. For instance,Thatwindoworsomestringorthelocationwould all is perfectly acceptable.

The keywords in the JavaScript language cannot be used in variables. Like Window,string,blooean and so on.

6.
JavaScript variable names is case-sensitive. Programmers in other languages is often tripped up by this one, as some languages is not sensitive-case in variable n Ames.

For instance, all of the following names would is considered completely different variable names in JavaScript: Gasbag gasbag gasbag gasbag

variable names are case-sensitive .

Summarize:

In general, variable names can only be made up of uppercase and lowercase letters and numbers, i.e. A-Z-a-Z 0-9 composition

You can only start with a letter or an underscore.

Cannot contain special characters, cannot use keywords as variable names.

-----------Welcome to Supplement

JavaScript Naming conventions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.