First, the object
Used to describe an abstract concept, people {properties, methods}
var car={type:"BYD",model:500,color:white,do:function(){"可以跑"}}
Object properties for use:
name = car.type;
Color = CAR [ "Color"]
using the method for the object:
Deal = car.do ()
Second, the definition and use of the function
1, a function of no arguments
function fun () {
statement thereof:
}
2, reference function
function fun (a, b) {
function thereof; // reflect the processing of a and b
}
3, the function returns a value:
Fun function () {
return result return;
}
Third, the variable (according to points scope variables):
1, local variables: variable declared inside a function, the function to use only the interior
2, global variables: variables declared outside of functions, all the scripts of the web pages and function can be used
four string handling
1, the string needs to have '' or '' quotes, you can use the subject under way to visit one of the characters in the string
2, a string of special characters if you need to print out, you need to use the escape character \, it is to make the transfer character maintain its original meaning, and not be treated as special characters to deal with.
3, using the string length string.length acquired, wherein an escape character \ is not
special characters: ' "\ \ r (carriage return) \ t (Tab) \ b ( backspace) \ F (feed)
4, the string can be treated as an object,
var s = new string ( 'test ');
equivalent to s = 'test;'
Properties: length prototype (add properties and methods to permit objects)
Method: charAt () Returns the specified character position of
the indexOf () Returns the index of the specified character
split () is divided into a character string array
substr (n) taken string, the first n characters removed
substring (a, b) to intercept a string of b-1 ()
toString () converts the object string
small letter the toLowerCase
the toUpperCase turn uppercase
Five, JS operator
Plus +
subtraction -
multiplication *
addition /
modulo%
increment ++
decrement -
assignment operator =
A + A = A =. 3. 3 +
A- =. 3. 3-A A =
A * A = A * =. 3. 3
A /. 3 = A = A /. 3
A% = A = A. 3%. 3
connected to the + sign
comparison operator
== equal size comparison
=== constant value equal to the size and type are consistent, JS is a weakly typed language
! = Not equal
<less than
> greater than
<= Less than or equal to
> = Greater than or equal to
the logical operators
&& and the. 1> 0 &&. 9>. 8 ---> to true
|| or or 1> 0 || 1 == 0 ----- > to true
! not non-1! = 2 ----> true
VI conditional:
IF (condition) {statement body;}
IF (condition) {statement body 1;} else {statement body 2;}
IF (condition 1) {statement body 1;} else if (condition 2) {statement body 2} else {3} statement executed is satisfied 3
SWITH (result)
{
Case A:
statement body. 1
Break;
Case B:
Statement body 2
Break;
.
.
.
Default:
Statement body n-;
}
Seven cycles:
. 1, for loop
for (before the loop begins executing; conditional execution; performed after the cycle) executed {statement}
var str = "ichunqiu", i = 0; // NOTE: i = 0 is for () of the first portion, can advance to represent and be initialized for (; I < STR .length-. 1;) { document.write ( STR [I] + "<br> ") I ++; // I ++ is for () of the third part, }
To traverse the object, var person = {name: "icq", age: 10, address: "beijin"}
var person={name:"icq",age:10,address:"beijin"};
var x,print="";
for (x in person){
print+=person[x]
}
document.write(print)
2, while loop
while (condition) {statement} // go body determination condition, the condition is satisfied, to judge before seeing the body
var i=1,sum=0; while(i<=100){ sum +=i; i++; } document.write(sum)
do {body statement} while (condition) to execute the statement // go body, determination conditions again
var i=1,sum=0; do{ sum+=i; i++ } while(i<=100); document.write(sum)
break out of the entire cycle is
var x=""; for (var i=0;i<10;i++){ if (i=3){ break; } document.write("本次数字为:"+i+"<br>") }
continue is out of the current cycle, it will still perform the subsequent cycle.
var x=""; for (var i=0;i<10;i++){ if (i=3){ continue; } document.write("本次数字为:"+i+"<br>") }