JS elevation reading notes (1-3 chapters)

Source: Internet
Author: User

First, JS Introduction

JS is a scripting language designed to interact with Web pages and consists of the following three different parts:

1.ECMAScript, defined by ECMA-262 (which defines these components of the language: syntax, type, statement, keyword, reserved word, operator, object), provides core language functions; (ECMAScript is a description of the language that implements all aspects of the standard ECMA-262 provisions.) )

2. The Document Object Model (DOM) is an application programming interface for XML but extended for HTML. The DOM maps the entire page into a multi-tiered node structure.

As in the following HTML page:

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Mytitle_dom</title></Head><Body>    <P>Hello world!</P></Body></HTML>

In the DOM, this page can be represented as a hierarchical node graph as shown in 1.1

3. Browser object Model (BOM), working with browser windows and frames.

To summarize, understand the following:

1.ECMAScript is the standard for the ECMA (European Computer Manufacturing Association) registration, in addition to the Microsoft JScript Standard and the Netscape JavaScript standard.
Both 2.dom and BOM are host objects in JavaScript.
Generally speaking, JavaScript refers to ECMAScript.

Second, the use of JS in HTML

2.1<script> elements

HTML4.01 defines the following 5 properties for <script>.

1) CharSet: Optional. Represents the character set of the code specified by the SRC attribute, and most browsers ignore this value.

2) Defer: Optional. Indicates that the script can be deferred until the document is fully parsed and displayed before execution.

3) Language: obsolete. Originally used to represent the scripting language used to write code, most browsers ignore this value.

4) src: Optional. Represents the external file that contains the code to execute.

5) Type: Required. Can be seen as an alternative attribute of language, a content type (also a MIME type) that represents the scripting language in which the code is written. Although both Text/javascript and Text/ecmascript have not been recommended, you can still see the frequent use of text/javascript. In fact, the MIME type used by the server when transmitting a JS file is usually application/x-javascript, but setting this value in type may cause the script to be ignored.

2.1.1 The location of the label

 By convention, all <script> elements should be placed in the

① can place the JS reference in the <body> element and place it behind the contents of the page.

The ② delay script,<script> tag defines the defer attribute. The purpose of this property is to indicate that the script executes without affecting the page construction, that is, the script is deferred until the entire page is parsed and then run.

The use of 2.1.2 in XHTML

In HTML, there are special rules that determine what content in the <script> element can be parsed, but these special rules do not apply in XHTML. such as the less than sign ("<") in XHTML requires "&lt", but you can use a CDATA fragment to contain the JS code

<type= "Text/javascript"><! [cdata[    function  Compare (A, b) {}]]</script> 
Iii. Basic Concepts

3.1 Variables

ECMAScript variables are loosely typed (which can be used to hold any type of data), and each variable is just a placeholder for a saved value. The var operator is used when defining a variable (var is a keyword) followed by the variable name (that is, an identifier).

Note: variables defined with Var in the function body are local variables that are destroyed when the function exits. However, after the variable defined in the function is omitted from the var operator, this variable is a global variable, so long as the function is called once, the variable is defined and can be accessed outside the function.

3.2 Data types

See http://www.cnblogs.com/wj204/p/3402204.html

3.3 operator

① unary operator:

Increment and decrement operators:

var s1= "2";

var s2= "Z";

var B=false;

var f=1.1;

var o={valueof:function () {return-1;}};

The s1++;//value becomes a number 3

s2++;//value becomes Nan

The b++;//value becomes a number 1

f--;//value becomes 0.100000000 (due to floating-point rounding errors)

The o--;//value becomes a number-2

Unary Plus and minus operators:

var s1= "01";

var s2= "1.1";

var s3= "Z";

var B=false;

var f=1.1;

var o={valueof:function () {return-1;}};

The s11=+s1;//value becomes a number 1

The s12=-s1;//value becomes a number-1

The s21=+s2;//value becomes a number 1.1

The s22=-s2;//value becomes a number-1.1

s31=+s3/-s3;//value becomes Nan

The b=+b/-b;//value becomes the number 0

The f11=+f;//value is still 1.1.

f12=-f;//value becomes-1.1

The o11=+o;//value becomes a number-1

The o12=-o;//value becomes a number 1

3.4 Functions

3.4.1 Understanding Parameters

The arguments in ECMAScript are internally represented by an array. This parameter array can be accessed by the arguments object in the body of the function to obtain each parameter passed to the function. In fact, the arguments object is just like an array, because each element of it can be accessed using square brackets syntax (i.e. the first element is arguments[0] and the second element is arguments[1])

function Howmanyargs () {

alert (arguments.length);

}

Howmanyargs ("string", 45); 2

Howmanyargs); 0

Howmanyargs (12); 1

Parameters-Related aspects:

① "Overloaded" Features:

function Doadd () {

if (arguments.length==1) {

alert (ARGUMENTS[0]+10);

}else if (arguments.length==2) {

Alert (arguments[0]+arguments[1]);

}

}

Doadd (10); 20

Doadd (30,20);//50

②arguments objects can be used with named parameters, such as:

function Doadd (num1,num2) {

if (arguments.length==1) {

alert (NUM1+10);

}else if (arguments.length==2) {

alert (ARGUMENTS[0]+NUM2);

}

}

Doadd (10); 20

Doadd (30,20);//50

In the rewritten Doadd () function, two named parameter num1,num2 are used with the arguments object. Because the value of NUM1 is the same as the value of arguments[0], they can be used interchangeably.

Note: named parameters that do not pass a value are automatically assigned the undefined value. This is the same as defining a variable without initializing it. (All parameters in the ECMAScript are passed as values, and arguments cannot be passed by reference.) )

3.4.2 Not overloaded

If two functions with the same name are defined in ECMAScript, then the name belongs only to the post-defined function (the previously defined function will not be valid) "To do overloading can be as 3.4.1.①, by examining the type and number of arguments in the function and reacting differently, which mimics the overloads of the method"

Summary:

The core language features of JavaScript are defined in ECMA-262 in the form of a pseudo-language called ECMAScript. ECMAScript contains all the basic syntax, operators, data types, and objects necessary to complete basic computational tasks, but does not provide a mechanism for obtaining input and generating output. Understanding ECMAScript and its numerous and complicated details is the key to understanding its implementation--javascript in Web browsers. Most implementations now follow the ECMAScript defined in ECMA-262 Third edition. The following is a brief summary of the basic elements in ECMAScript:

The basic data types in ①:ecmascript include Undefined,null,boolean,number and string;

②:ecmascript does not define separate data types for integer and floating-point values, and the number type can be used to represent all values;

③:ecmascript also has a complex data type, the type of object, which is the underlying type of all objects in the language;

④:ecmascript provides many of the same basic operators as C and other C languages, including arithmetic operators, Boolean operators, relational operators, equality operators, and assignment operators.

⑤:ecmascript has drawn many flow control statements from other languages, such as the IF statement, the for statement, and the switch statement. Functions in ECMAScript differ from functions in other languages (not noted)

⑥ does not need to specify a function's return value, because any ECMAScript function can return any value at any time.

7: A function that does not specify a return value returns a special undefined value. There is also no concept of a function signature in ECMAScript, because its function parameters are passed in a form of an array of 0 or more.

JS elevation reading notes (1-3 chapters)

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.