JavaScript distilled basic knowledge and function _javascript skills

Source: Internet
Author: User
One, operator
Copy Code code as follows:

. [] () property access and function calls
Delete new typeof +-! Unary operator
*/% multiplication, division, modulo
+-addition/connection, subtraction
>= <= > < inequality operators
= = =!== equality operator
&& Logic and
|| Logical OR
?: Ternary operator


second, the statement:
1.if statement
Copy Code code as follows:

var dayofweek=0;
if (day===6) {
}
else if (dayofweek===0) {
}
else{
}

2.switch Statement
Copy Code code as follows:

var dayofweek=0;
Switch (DayOfWeek) {
Case 6:
Break
Case 0:
Break
Default
Break
}

The switch statement precisely matches the value of the switch expression to all specified case expressions (= =). Executes the statement in the matching case clause when a match is found. If no match is found, an optional default statement is executed.
3.while Statement
Copy Code code as follows:

var count=0;
while (count<=10) {
count++;
}

4.do/while Statement
Copy Code code as follows:

var count=0;
do{
count++;
}while (count<=10);

5.for Statement
Copy Code code as follows:

for (Var count=0;count<=10;count++) {
}

6.for/in Statement
Copy Code code as follows:

var colors=["Red", "Yellow", "Blue"];
for (var color in colors) {
}

7.try/catch Statement
Copy Code code as follows:

try{
}
catch (e) {
}

8.throw Statement
Copy Code code as follows:

throw{
Name: ' Argumentoutofrangeerror ',
Message: ' Year must > 0 '
}

9.return Statement
return "Red";
The return statement causes a function to be returned in advance. It can also specify the value to be returned. If no return expression is specified, the value is undefined.

third, type:
1. Digital
var value=1.0;
JavaScript has only a single numeric type. He is represented internally as a 64-bit floating-point number.
Special values:
NaN is not a special value of a number
Special value of Infinity infinity
2. String
var value= "one";
A JavaScript string is a sequence consisting of 16-bit Unicode characters. String literals can be enclosed in single or double quotes.
String escape:
\" \' \\
\b Backspace
\f Page Breaks
\ n Line Feed
\ r return character
\ t tab
\uxxxx Unicode characters specified by the 4-bit 16-forward XXXX
3. Boolean value
var value=true;
The Boolean value has only 2 values: True and False.
The following values are treated as false values:
False
Null
Undefined
Empty string '
Number 0
Number Nan
4.null
var value=null; Null
In JavaScript, NULL is a special value that represents "no value".
5.undefined
var value; Undefined
Undefined in JavaScript is a special value. Undefined is returned when an undeclared variable is used, a variable that is declared but not yet assigned, and an object property that does not exist.
6. The object
Copy Code code as follows:

var car={
Brand: "Honda",
Color: "Red",
Run:function () {
Run
}
};
var Value=car.brand;

Objects in JavaScript are a variable set of key values. Objects are containers of properties, each of which has a name and a value. The name of the property can be any string, including an empty string. The property value can be any value other than the undefined value.
Copy Code code as follows:

Car.prototype.stop=function () {
Stop
};
Car.run ();

Each object is connected to a prototype object, and it can inherit the property from it. The prototype connection does not work when it is updated. It is used only when retrieving values.
Modular:
Copy Code code as follows:

var app={};
app.employee={
Name: "Joyce"
}
app.customer={
Name: "Jason"
}

7. function
Copy Code code as follows:

var add=function (a,b) {
return a+b;
};
Add (1+2);

A function in JavaScript is an object. Functions can be defined in other functions. An intrinsic function can access the arguments and variables of the external function that surrounds it. This is called closure.
Closures:
Copy Code code as follows:

var car=function (Brand,color) {
return {
Getbrand:function () {
return brand;
},
Getcolor:function () {
return color;
}
};
};
var mycar=car ("Honda", "Red");
Mycar.getbrand ();

Functional Inheritance:
Copy Code code as follows:

var mammal = function (spec) {
var that = {};
That.getname = function () {
return spec.name;
};
That.says = function () {
return Spec.saying | | '';
};
return to 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 to that;
};
var Mycat = Cat ({name: ' Henrietta '});

8. Array
var colors=["Red", "Yellow", "Blue"];
var value=colors[0]; "Red"
Arrays are the same set of key values as objects. The difference is that an array can be a property name with an integer. Arrays also provide a very useful set of built-in methods.
Each array has a length property. The value of the length property is the maximum integer property name of this array plus 1. It does not necessarily equal the number of attributes in the array.
9. Regular expressions
Copy Code code as follows:

var numberregex=/^-?\d+ (?: \. \d*)? (?: e[+\-]?\d+)? $/i;
Numberregex.test (1.2); True

Regular expression groupings:
() Capture grouping
(?:) non-capture groupings
Regular expression escape:
\\ \/ \[ \] \( \) \{ \} \? \+ \* \| \. \^ \$
\f Page Breaks
\ n Line Feed
\ r return character
\ t tab
\uxxxx Unicode characters specified by the 4-bit 16-forward XXXX
\d matches a number (equivalent to [0-9])
\1 Capture grouping 1 references (\2, and so on)
Regular Expression class escape:
\- \\ \/ \[ \] \^
\b Backspace
\f Page Breaks
\ n Line Feed
\ r return character
\ t tab
\uxxxx Unicode characters specified by the 4-bit 16-forward XXXX
\d matches a number (equivalent to [0-9])
Regular expression quantifiers:
? Match 0 or 1 times (same {0,1})
* Match 0 or more times (same as {0,})
+ match 1 or more times (same {1,})
{n} matches n times
{N,} matches at least n times
{n,m} matches at least n times, but not more than m times
Regular expression Flags:
G Perform a global match (all matches)
I performs a case-insensitive match
M performs multiple lines matching (^ and $ can match line terminator)
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.