Detail analysis in JavaScript

Source: Internet
Author: User

JavaScript case sensitive: In JavaScript, variables and functions are case sensitive. For example:
Copy codeThe Code is as follows:
Function myfunction () {} and
Function myFunction () {} is different

The core objects such as Array and Object in JavaScript are case sensitive.

Single quotation marks and double quotation marks: this problem occurs when SQLServer concatenates a string "select * from page where name = 'lida: are the three backticks in front of double quotation marks or single quotation marks in front of them? I learned more. Double quotation marks are used by programming languages, and single quotation marks indicate the string type by SQLserver. However, there is no special difference between single quotation marks and double quotation marks in JavaScript, and they can be used to create strings. However, in general, JavaScript must use double quotation marks for single quotation marks, HTML, and other attribute values. At the same time, single quotation marks can include double quotation marks, double quotation marks can also contain single quotes. In special cases, the escape character "\" is required. For example:
Copy codeThe Code is as follows:
Var temp = '<p class = "nameA"> What \'s this? ';

The role of parentheses: Like other languages, parentheses in JavaScript are also two functions. One is used as a separator, for example: (1 + 1) * 2; the other is an expression, for example: (1 + 1) * 2; the second function is the expression. For example, the separated parentheses in (function () {}) () are separators, and the following parentheses indicate the execution method.

Function call and reference:
Copy codeThe Code is as follows:
Var temp = myFunction ();
Var temp = myFunction;

Because parentheses can represent execution, the first temp represents the return value of the myFunction function, and the second temp represents assigning the myFunction to temp. For example:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
// JavaScript Document
(Function (){
Function $ (){
Alert ("Buffering! ");
}
Window ['ld '] = {}
Window ['ld '] [' $ '] = $;
}
)();
Window. onload = LD. $;
</Script>

The webpage can be loaded normally, because this means that the $ method is assigned to window. onload, and the page load runs the self-compiled $ () function. If you replace this sentence
Window. onload = LD. $ (); the running result is as follows; "Buffering in progress" is displayed first, and then

This is because the onload event does not require a return value, and the $ function does not return a value, which leads to unimplemented errors.
Line feed: No matter which quotation marks are used to create a string, it cannot contain a forced line break. As follows:
Copy codeThe Code is as follows:
Var temp = '

<Ol>
</Ol>'

This will cause a parsing error. You can use \ or + to wrap the line:
Copy codeThe Code is as follows:
Var temp = '

<Ol> \
</Ol> \
';

Braces and semicolons are optional:
In JavaScript, semicolons and braces are not mandatory. For example, alert ('A'); and alert ('A') are no different, but they are run differently in the if statement, it is best not to omit it.
Heavy Load
JavaScript is a prototype-Based Object-Oriented function without any overload in C #. Here we can call it replacement. A function with the same name will execute the last function with the same name regardless of the number of parameters, for example, function alert () {} will overwrite the alert function in JavaScript.
Scope and Closure
You can participate in my blog "Scope chain and closure in JavaScript".

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.