Cliché JavaScript variable naming conventions and annotations _ basics

Source: Internet
Author: User
Tags reserved

Simply put, the identifier naming rules are as follows:

The first character can be any Unicode letter, and a dollar sign ($) and an underscore (_).

The second and subsequent characters can also be used as numbers.

These are all valid identifiers.

arg0
_tmp
$elem
Pi

The following are illegal identifiers.

1a
23
***
A+b
-D

Chinese is a valid identifier and can be used as a variable name.

var temporary variable = 1;

JavaScript has some reserved words that cannot be used as identifiers: arguments, break, case, Catch, class, Const, continue, debugger, default, delete, do, else, enum, Eval, export, extends, false, finally, for, function, if, implements, import, in, instanceof, interface, let, new, NULL, Package, private, protected, public, return, static, super, switch, this, throw, true, try, typeof, Var, void, while, with, Yield

In addition, there are three words, although not reserved words, which, because of their special meaning, should not be used as identifiers: Infinity, NaN, undefined.

The part of the source that is ignored by the JavaScript engine is called a comment, and its role is to interpret the code. JavaScript provides two kinds of annotations: one is a single-line comment, with//head, and the other is multiline comment, placed between/* and/*.

This is a single-line comment

/*
This is
MultiRow
Comments
*/

The code section later in this tutorial uses both forms to illustrate the results of your code and what you need to be aware of.

In addition, because of historically JavaScript-compatible comments for HTML code, <!--and--> are also treated as single-line annotations.

x = 1; <!--x = 2;
--> x = 3;

In the code above, only x = 1 is executed, and the rest is commented out.

Note that,--> is treated as a single-line annotation only at the beginning of the line, otherwise it is an operator.

function countdown (n) {while
 (n--> 0) Console.log (n);
}
Countdown (3)
//2
//1
//0

In the code above, n--> 0 is actually treated as n--> 0 because the output is 2, 1, and 0.

The above is a small series for everyone to bring the cliché JavaScript variable naming norms and comments of the entire content, I hope to help you, a lot of support cloud Habitat Community ~

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.