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