1 JS Basic (Super Simple) 1.1 data type 1.1.1 Basic type:
1) Number: Special Note: Nan detection method: Nan!=nan; or using the isNaN method
2) string
3) Boolean
4) NULL
5) undefined
1.1.2 Complex Types
Object:date,array,function
1.2 Variables
var variable name = value
Scope of the variable: 1. Global: in pages. 2 Local: The function is the unit.
1.3 typeof
Function: The type typeof (variable) or typeof variable of the detection variable
1.4 Conversion between data types 1.4.1 to number
Implicit: arithmetic operator: +-*/
Explicit: Number () parseint (), parsefloat ()
1.4.2 Turn string
Implicit: + ""
Explicit:. ToString (), String ()
1.4.3 Turn Boolean
Implicit:!! A
Explicit: Boolean ()
Features of 1.5 JS
1) Weak type: var variable name, all variables declared using the var keyword, do not have to divide the data type
2) Dynamic: Can dynamically add variables to arrays, objects, can also be dynamically deleted, that is, you can change the length of the array, the properties of the object.
3) scripting language: Edge compilation, Edge execution
1.6 Language structure
Sequential structure
Conditional structure: If If-else
Branch structure: if-else-if switch case
Loop structure: While do and for
1.7 Writing
<script src= "Location" ></script> or <script></script>
1.8 functions
Function name (argument list) {Functional Body}
Return:return parameter; Returns the corresponding argument, returns immediately after that, the code is no longer executed, is not written, or no arguments are followed, returns undefined; you want to return multiple values: using arrays or objects;
Note: The functions inside JavaScript are not overloaded (different parameters with the same name)
1.8.1 Pre-parsing
When JavaScript is running, the parameter/function declaration and the specific parameters are placed at the front.
1.8.2 Anonymous functions
function (argument list) {Functional Body}
Typically used for: bundle events.
1.8.3 function expression
var variable name =function (argument list) {function Body}
Call: Function name ()
Output the entire function content (including function declaration and function body): Using the function name,
1.8.4 self-executing functions
(function () {Functional body}), or (function () {function Body} ());
Generally used for: one-time execution; advantages: Avoid duplicate function names.
1.8.5 callback function
To use a function as a parameter
Function name (argument, function 1 (formal parameter) {function Body});
1.9 Built-in objects 1.9.1 Math
Math.floor (): Rounding Down
Math.ceil (): Rounding up
Math.Round (): Rounding
Math.random (): 0-1 random numbers
Math.Abs (): Absolute value
Math.pow (b): Power of a
Math.max (A, B): Take maximum value
Math.min (A, B): Take the minimum value
1.9.2 Array
Output string
ToString ():. tostring=0; array empty
ValueOf ();: Returns itself
Slice (A, B): Gets the index a<= content <b
Reverse ();: Invert array contents
Sort (function (A, b) {return-A-B}): Sort returns a value based on the callback function, negative values are unchanged, and positive values are swapped positions. This is ascending
IndexOf (A, b);: Gets the index of a and finds it starting with B
LastIndexOf (A, b);: Look forward to the index of a, and start looking
Join (a);: combination of a element with a string, the original array unchanged
Push (a): Append element A,
Concat (a): Append array A to tail
Pop (): Delete last
Shift (): Move left
Unshift (a): Move right, fill with a
Splice (A,[b],[c]): Gets the B content after index A, replacing it with C. Splice (0,arr.lenght) empty array
Filter (function (Item,index,arr) {if (item>200) return true;}) : Filter, callback function three parameters represent: value, index, entire array. Returns true to leave, false to filter out.
ForEach (function () {}): Iterates over the array, three parameters of the callback function,
1.9.3 Date
Convert to Date Object
var date=new date (y,m,d); Y year (m+1) month D Day
var date=date.parse ("y-m-d");
var date=new date ("y-m-d");
Get milliseconds:
var date=date.now ();
var date=+new date ();
New Date (). toString ();
New Date (). ValueOf ();
Get part
. getFullYear ();
. GetMonth ();
. GetDate (); ' What
. GetDay (); Day of the Week
. GetHours ();
. getminutes ();
. Getsecends ();
. getmilliseconds ();
. GetTime (); The number of milliseconds to this point;
1.9.4 String
Get index
IndexOf (A, b); Gets the index of a and finds it starting with
LastIndexOf (A, b); Look forward to the index of a
Get character
. CharAt (a); output index of a character
. charCodeAt (a); Ascll code for characters with an output index of a
Remove space before and after
. Trim ();
Convert case
to (Locale) uppercase ();
to (Locale) lowercase ();
Other operations
. concat (); connection
Slice (A, B): Get a<= content <b
. substring (A, b);: Get a<= content <b; same as above
. substr (A, b);: Gets the second content after a
. replace (b);: Change A to B;
Split (A, b);: Use a split string, return an array, get the first
1.10 Custom Object 1.10.1 by constructor 1
var object name =new ();
Object name. property = value;
The name of the object. Method =function (parameter list) {method body};
Use
The object name. Properties;
Object name. Method (parameter);
1.10.2 by Constructor 2
function constructor Name (argument list) {
var object name =new ();
Object. property = value;
Object. Method =function (parameter list) {
Method body;
};
return object;
}
Use
var object = constructor Name (parameter);
The object name. Properties;
Object name. Method (parameter);
1.10.3 by Constructor 3
Function name (argument list) {
this. Attribute = value;
This. Method name =function (parameter list) {
Method body;
};
}
Use
Var object =new constructor Name (parameter);
The object name. Properties;
Object name. Method (parameter);
1.10.4 by Object literal
var object name ={
Property: Value,
Method Name: Function (argument list) {
Method body;
}
}
Use
The object name. Properties;
Object name. Method (parameter);
Watch out.
Use commas to separate attributes
1.10.5 JSON
Key-value pairs
var object name ={
"Properties": Value,
"Method Name": function (argument list) {}
}
Use:
The object name. Properties;
Object name. Method (parameter);
Note: The difference from the object literal is that the attribute name needs to use quotation marks
JS Basics (Super Simple)