Javascript Learning (2) javascript FAQs _ basic knowledge-js tutorial

Source: Internet
Author: User
When using js, I often encounter some problems. I used my spare time to sort out some common problem solutions and post them to share with you, if you have any need, refer to section 1. Javascript Chinese and variables are case sensitive.

2. Single quotes and double quotes can be used to create strings without special differences in JavaScript. However, as a general rule, most developers prefer to use single quotes instead of double quotes, but the XHTML specification requires that all attribute values be enclosed in double quotes. In this way, the single quotation marks are used in JS, and the use of double quotation marks on XHTML makes the code of the two more convenient and clearer.
Single quotes can contain double quotes. Likewise, double quotes can also contain single quotes.

3. Brackets
Note that the brackets in Javascript contain two types of semantics, which can be a separator or expression.
A. delimiter everyone is very familiar with (1 + 3) * 3 equals 12
B. (function () {}) (); a pair of parentheses before the function is used as the separator. The parentheses below indicate that this method is executed immediately.

4. function call and reference
Because parentheses represent execution, so:
Var foo = example (); foo indicates the return value of the function.
Var foo1 = example; assign the function reference to a value of foo1

5. Heavy Load
JS does not support overloading. Therefore, here, overloading is more similar to replacement.
JS no difference in the number of parameters

6. Scope and Closure
Scope refers to the code space that has access permissions to a property or method. For example:

The Code is as follows:


Function myFunction (){
Var temp = "abc ";
}


The above temp cannot be accessed outside the function.
A closure is a concept related to the scope. It refers to the attributes of an internal function even after the external function is executed and terminated.

Here is an example of the scope and closure.:
Create the following html page:

The Code is as follows:






Untitled document

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.