JavaScript summary
What is 1.JavaScript? Dynamic, weak type
(from w3school:http://www.w3school.com.cn/js/index.asp)
JavaScript is a scripting language that belongs to the web!
JavaScript is used by millions of of pages to improve design, verify forms, detect browsers, create cookies, and more.
JavaScript is the most popular scripting language on the Internet.
2. Implementation: <script type= "Text/javascript" ></script> tags.
3. Statements, comments, identifiers (variable names, function names), reserved words
4. Variable: Weak type
Variable type is variable
5. Data type: typeof operator
Undefined
Null = = undefined
Boolean (Type conversion: if (' yes ') {...})
Number Nan!=nan, IsNaN, type conversion parseint ("1234.5abc"), parsefloat ()
String type conversion: 12.toString () Single quotation mark, double quotation mark
function: Types of functions
6. Operator: Basic and Java almost, where "= =" refers to the comparative content, Eg:var a= "123"; var b=123;alert (a==b);//true
"= = =" is the comparative content and type, Eg:var a= "123"; var b=123;alert (a===b);//false
7. Control statement: Almost as basic as Java
8. Functions
1) General definition and invocation
2) Dynamic parameter arguments, the following example:
1 function Plus () {2 //Parameter object (array)3 if (arguments.length>0) {4 var sum=0;5for (Var i=0;i<arguments. length;i++) {6 sum+=arguments[i];7 }8 }9 return sum;Ten } One //Call A var x=plus (10,20,30,40); - alert (x);//=100
3) anonymous definition and invocation, anonymous function definition, define anonymous function, assign function address to variable
9. Basic type (undefined,null,number,boolean,string)/reference type: Object, Array, Function
1) Dynamic Properties: Delete P.name
2) Copy the reference:
var o1=new Object (); var o2=o1;o1.name= ' Ada '; alert (o2.name);//ada
3) Pass parameters cannot change external objects within the function by parameters
4) Type detection instanceof
10. Scope: Valid range of variables
1) Execution environment; each function is an execution environment
2) Scope chain
3) Search variables
4) No block-level scope
5) the declaration variable (VAR) is automatically added to the nearest environment, and the variable is not declared directly to the global environment
Two ways to create 11.Object
1) New Object ()
2) {"Name": "Ada", "Sex": "Male"}//json mode
Eg://object how objects are created
1.newvar p=new Object ();p. name= "Ada";//2.jsonvar p={"name": "Ada", "Sex": "Male"};alert (p.name); alert (p.sex);// Property access Alert (p["name"]), alert (p["sex"]);//Traverse All properties for (Var A in P) {document.write (P[a]);}
12.Array
1) Create: New Array ();
1.var a=new Array (4), alert (a.length),//2.a[0]=1;a[1]=2;a[3]=4;alert (a[2]);
2) Create and initialize: a=[1,2,3];
3) Array Dynamics
var A=[1,2,3];a[10]=11;alert (a.length),//11alert (A[3]),//undefined//a[3]---a[9] all undefined
4) Conversion: ToString ()
5) Push (): Add tail element
var a=[1,2,3];a.push (4);//press Stack alert (a);//1,2,3,4
6) Shift (): Delete header element
var a=[1,2,3,4];var x=a.shift (); alert (x);//2,3,4
7) Sort (a,function (v1,v2) {}), sorting
var a=[15,1,3,5,20,50];a.sort (function (v1,v2) { if (v1>v2) { return 1; } else if (v1<v2) { return-1; } else{ return 0; }}); alert (a);//order, small to large, 1,3,5,15,20,50
8) Slice (start,end) intercept
var a=[1,2,3,4,5,6,7,8];var b=a.slice (2,6); alert (b);//3,4,5,6
9) Splice: Delete (0,2), insert (2,0, "AAA"), replace (2,1, "AAA")
IndexOf, returns the position of the first occurrence of a specified string value in a string
One) Arr.foreach (function (Item,index,array) {});//Iteration
Arr.every/arr.some)
Filter, eg: filter: 10 + elements
var A=[15,2,12,3,5,11,18];var b=a.filter (function (item,index,array) {return item>10;}); alert (b);//15,11,18
13.Date:
1) Create new date ()/new date (2010,5,6,14,25,30)
2) Date.now ()
3) Date.gettime ()/getyear ()/getmonth ()/getday ()/getdate ()
14.Function
1) function as parameter value
2) Caller
function A () {B ();}
function B () {alert (b.caller);}
3) The function is an object:
Length property, number of arguments
Apply (); call (); window.color= "Red"; var O={color: "Blue"}function Saycolor () {alert (this.color);} Saycolor.call (window); Saycolor.call (o); var osaycolor=saycolor.bind (o); Osaycolor ();
15.Global Ultimate Object
eval method, converting a string to an expression
Eg:var Jstu=eval ("(" +jstr+ ")");//code injection attack, less use
16.Math objects (from w3school:http://www.w3school.com.cn/jsref/jsref_obj_math.asp)
Method Description
ABS (x) The absolute value of the return number.
ACOs (x) returns the inverse cosine of the number.
ASIN (x) returns the inverse chord value of the number.
atan (x) returns the inverse tangent of x with a value between-PI/2 and PI/2 radians.
atan2 (y,x) returns the angle from the x-axis to the point (X, y) (between-PI/2 and PI/2 radians).
ceil (x) is rounded on the logarithm.
cos (x) returns the cosine of the number.
exp (x) returns the exponent of E.
Floor (x) is rounded down with a logarithmic.
log (x) returns the natural logarithm of the number (bottom is e).
Max (x, y) returns the highest value in X and Y.
min (x, y) returns the lowest value in X and Y.
the POW (x, y) returns the y power of X.
random () returns an arbitrary number between 0 and 1.
round (x) rounds the number to the nearest integer.
sin (x) returns the sine of the number.
sqrt (x) returns the square root of the number.
Tan (x) returns the tangent of the angle.
Tosource () returns the source code of the object.
valueOf () returns the original value of the Math object.
2016-10-13
Beginner Java10:javascript Summary (i.)