Javascript naming rules and javascript namespaces

Source: Internet
Author: User

Javascript naming rules and javascript namespaces

JavascriptCase Sensitive(Keyword, function name, variable name, etc.), the first character of the identifier must beLetter, underline, or $ characterThe subsequent characters can contain numbers.

If the voice indicates that the variable is not assigned a value, the default value is undefined.

Javascript does not distinguish between integer and floating point types,All numbers are represented in the floating point type.Of

The string type is enclosed in single or double quotation marks.

Escape characters

Escape Sequence characters

/B Return

/F form feed

/N line feed

/R press ENTER

/T horizontal hop (Ctrl-I)

/'Single quotes

/"Double quotation marks

// Backslash

Note: When Using escape characters in the document. writeln () function, the script must be placed in the <pre> </pre> label pair.

 

Javascript hasAbsolutely equalConcept, "=" indicates equal to, only determines the literal value, does not involve the data type, for example, "17" = 17, the return value is true, "=" indicates that it is absolutely equal to, and involves data type comparison. For example, "17" = 17, and the return value is false.

 

The typeof function is used to return the Data Type of Its operands,

var a=3;var b="name";var c=null;
 

Typeof a Returns number, typeofb returns string, typeof c returns object,

Typeof can return the following types: number, string, boolean, object, function, and undefined.


The following two statements are specifically used for object statements:

For... in Loop

Var objects = {user: "clf", age: "25", QQ: "496221132"}; for (var item in objects) {document. write ("attribute:" + item + "=" + objects [item] + "<B/r> ");}

Result:

Attribute: user = clf

Property: age = 25

Property: QQ = 496221132

 

With statement, used to avoid repeated use of the specified object reference

Var date_time = new Date (); with (date_time) {alert (getYear () + "/" + getMonth () + 1 + "/" + getDate ()); // if it is not in the with statement block, it should be alert (date_time.gerYear ())...}
 

Use parentheses instead of braces to create arrays in javascript,

var arr = new Array('a','b','c');var arr2 = new Array(7);

Same-origin policy

The same-origin policy is the main security policy of javascript. It indicates that a script can only read the properties of windows or documents with the same source.

The same-origin check is used to check whether two URLs belong to the same source. The following conditions must be met:

1. The protocol is the same

2. The port is the same

3. The domain name is the same



 

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.