I. Operators
CopyCode The Code is as follows:. [] () attribute access and function call
Delete new typeof + -! Unary operator
*/% Multiplication, division, modulo
+-Addition, connection, and Subtraction
>=<=> <Inequality operator
===! = Equality operator
& Logic and
| Logical or
? : Ternary Operator
Ii. Statements:
1. If statementCopy codeCode: var dayofweek = 0;
If (Day = 6 ){
}
Else if (dayofweek === 0 ){
}
Else {
}
2. Switch statement
Copy codeCode: var dayofweek = 0;
Switch (dayofweek ){
Case 6:
Break;
Case 0:
Break;
Default:
Break;
}
The switch statement precisely matches the value of the switch expression with all specified case expressions (= ). When a match is found, the statement in the matched case clause is executed. If no matching is found, the optional default statement is executed.
3. While statement Copy codeThe Code is as follows: var COUNT = 0;
While (count <= 10 ){
Count ++;
}
4. Do/while statement Copy codeThe Code is as follows: var COUNT = 0;
Do {
Count ++;
} While (count <= 10 );
5. For statement
Copy codeThe Code is as follows: for (var count = 0; count <= 10; count ++ ){
}
6. For/in statements
Copy codeThe Code is as follows: var colors = ["red", "yellow", "blue"];
For (VAR color in colors ){
}
7. Try/catch statements Copy codeThe Code is as follows: Try {
}
Catch (e ){
}
8. Throw statement Copy codeThe Code is as follows: Throw {
Name: 'argumentoutofrangeerror ',
Message: 'year must> 0'
}
9. Return Statement
Return "red ";
The Return Statement returns a function in advance. It can also specify the value to be returned. If no return expression is specified, the value is undefined.
3. Type:
1. Number
VaR value = 1.0;
JavaScript has only one numeric type. It is internally represented as a 64-bit floating point number.
special value:
special value of Nan not numeric
special value of infinity
2. string
VaR value = "one";
a javascript string is a 16-bit Unicode string. Strings can be enclosed in single quotes or double quotation marks.
string escape:
\ "\ '\
\ B Return character
\ f break
\ n linefeed
\ r return character
\ t tab
\ uxxxx is a Unicode Character specified by four hexadecimal XXXX characters
3. boolean value
VaR value = true;
the Boolean value has only two values: true and false.
the following values are treated as false values:
false
null
undefined
Null String ''
number 0
Number Nan
4. null
VaR value = NULL; // null
null in Javascript is a special value, indicating "no value ".
5. undefined
VaR value; // undefined
undefined is a special value in JavaScript. Undefined is returned when an undeclared variable, a declared but not assigned value, or an object attribute does not exist.
6. the copy Code code of the object is as follows: vaR car = {
brand: "Honda",
color: "red",
Run: function () {
// run
}< BR >};
VaR value = car. brand;
Objects in JavaScript are variable key-Value Sets. An object is a property container. Each property has a name and a value. The attribute name can be any string including an empty string. The attribute value can be any value except the undefined value.Copy codeThe Code is as follows: car. Prototype. Stop = function (){
// Stop
};
Car. Run ();
Each object is connected to a prototype object and can inherit attributes from it. The prototype connection does not work when it is updated. It is used only when the value is retrieved.
Modularization:Copy codeCode: var app = {};
App. Employee = {
Name: "Joyce"
}
App. Customer = {
Name: "Jason"
}
7. FunctionsCopy codeThe Code is as follows: var add = function (a, B ){
Return A + B;
};
Add (1 + 2 );
Functions in JavaScript are objects. Functions can be defined in other functions. An internal function can access parameters and variables of external functions that enclose it. This is called a closure.
closure: copy Code the code is as follows: var car = function (brand, color) {
return {
getbrand: function () {
return brand;
},
getcolor: function () {
return color;
}< BR> };
};
var mycar = car ("Honda", "Red");
mycar. getbrand ();
function-based inheritance:
copy Code the code is as follows: var mammal = function (SPEC) {
var that ={};
that. getname = function () {
return spec. name;
};
that. says = function () {
return spec. saying | '';
};
return that;
};
var mymammal = mammal ({Name: 'herb '});
var cat = function (SPEC) {
spec. saying = spec. saying | 'meow ';
var that = mammal (SPEC);
that. purr = function (n) {
// purr
};
that. getname = function () {
return that. says () + ''+ spec. name + ''+ that. says ();
};
return that;
};
var MyCat = CAT ({Name: 'henrietta '});
8. array
var colors = ["red", "yellow", "blue"];
VaR value = colors [0]; // "red"
arrays and objects are a set of key values. The difference is that the array can use an integer as the attribute name. Array also provides a very useful set of built-in methods.
Each array has a Length attribute. The value of the Length attribute is the maximum integer property name of the array plus 1. It is not necessarily equal to the number of attributes in the array.
9. regular Expression copy Code the code is as follows: vaR numberregex =/^ -? \ D + (?: \. \ D *)? (?: E [+ \-]? \ D + )? $/I;
numberregex. Test (1.2); // true
Regular Expression grouping:
() Capturing group
(? :) Non-capturing group
Regular Expression escape:
\\\/ \ [\] \ (\) \{\}\? \ + \ * \ | \. \ ^ \ $
\ f linefeed
\ n linefeed
\ r carriage return
\ t tab
\ uxxxx consists of four hexadecimal characters unicode Character specified by XXXX
\ D matches a number (equivalent to [0-9])
reference of capture type group 1 (\ 2 and so on)
regular expression class escape:
\-\/\ [\] \ ^
\ B Return character
\ f break
\ n line break
\ r carriage Return
\ t tab
\ uxxxx is a Unicode Character specified by four hexadecimal XXXX characters
\ D matches a number (equivalent to [0-9])
Regular Expression quantifiers:
? Match 0 or 1 times (same as {0, 1})
* match 0 or multiple times (same as {0 ,})
+ match 1 or multiple times (same as {1,})
{n} match n times
{n ,} match at least N times
{n, m} matches at least N times, but cannot exceed M Times
Regular Expression flag:
G performs global match (all matches)
I perform case-insensitive match.
M performs multi-row match (^ and $ can match the row Terminator.)