Composition of browser
- shell
- Kernel part
- Rendering engine (syntax rules and rendering)
- js engine
Javascript consists of three parts: ECMAScript, DOM and BOM
Compiling language: C, C + +,
- Advantages: fast
- Insufficient: poor portability (not cross platform)
Interpretation language: Javascript
- Advantages: cross platform, single thread
- Insufficient: slightly slow
Mainstream browser kernel
IE trident
Chrome blink/webkit
firefox Gecko
Opera presto
safari webkit
data type
Original value:
Number,Boolean,String,undefined,null
Reference value:
array, Object, function ········ date, Regexp
Any type + string is equal to string
a + +: execute before operation
++a: Operation before execution
&&Operator stops when it encounters false
||Operators stop when they encounter the truth
typeof: number,string,boolean,object,function,undefined
-
Number: convert type data to number
-
parselnt (string, radius): convert data to integer · - 123abc=123
-
parseFloat (string): convert data to floating point
-
String: convert data into a string
-
Boolean: convert data type to Boolean value (true, false)
typeof (a): undefined / / no variable declared
arguments: argument array (argument list)
Return: terminate the function and return the value
typeof(null): object
Most of the number symbols are converted to number type -- NAN is the one that cannot be converted
algorithm
recursion
Class array
-
If the attribute is an index (numeric) attribute, it must have a length attribute, and it is best to add push
-
Once you add a splice method to an object, the object looks like an array
var obj={ "0" :"a", "1":"b", "2":"c", age:123, name:"abc", length:3, push:Array.proyotype.push, splice:Array.proyotype.splice }
- Principle of class array push
Array.prototype.psh=function (target){ obj[obj.length]=target; obj.length++; }
time stamp
Get the total number of milliseconds of Date, not the number of milliseconds of the current time, but the number of milliseconds since January 1, 1970
- Through valueof() getTime()
var date=new Date(); console.log(valueof()); console.log(getTime());
- Simple writing method (the most commonly used writing method)
var date=+new Date(); console.log(date);
- H5 total number of milliseconds added
console.log(Date.now());
Array string jion() and split();
var str='12345'; str.split('')//['1', '2', '3', '4', '5'] var arr=[1,2,3,4,5] arr.jion('-')//1-2-3-4-5 arr.jion('')//12345 arr.jion()//1,2,3,4,5 //Using the jion() method is a string type
Detect whether it is an array
- instanceof operator, which can be used to detect whether it is an array
var arr[]; console.log(arr instanceof Array);//true
- Array. Isarray (parameter); H5 newly added ie9up
console.log(Array.isArray(arr));//true
Original array change
- push() adds one or more array elements to the end of our array;
- unshift() adds one or more array elements at the beginning of our array;
- pop() deletes the last element of the array; Only one element is deleted at a time, so no parameters are required. The deleted element is returned;
- shift() can delete the first element of the array;
Returns the index number of an array element
Indexof (array element) is used to return the so number of the array element and search from the front
It only returns the first index number that meets the condition,
If it cannot find an element in the array, the returned time is - 1;
LastIndexOf (array element) find from the back
Convert array to string
- toString() converts our array to a string
var arr=[1,2,3]; console.log(arr.toString());//1,2,3
- Join (separator)
var arr1=['green','blue','red']; console.log(arr1.join());//green,blue,red console.log(arr1.join('-'));//green-blue-red
The string object returns the position indexOf according to the character ('string to find ', [starting position] optional)
Returns characters based on position
1.charAt(index) returns characters according to the position;
var str='andy'; console.log(str.charAt(3))//y //Traverse all characters for(var i=0;i<srt.length;i++){ console.log(str.charAt(i)) }
-
charCodeAt(index) returns the character ASCII value of the corresponding index number. Purpose: to judge which key the user pressed
-
str[index];
Operation method of string
- concat('string ',' string 2 '...),, connection string
var str='andy'; console.log(str.concat('red'));//andyred
- sbustr('Start position of interception ',' several characters of interception ');
var str1 ='The spring breeze of reform is blowing all over the ground'; console.log(str1.substr(2,2));//Spring breeze / / the first 2 is the 2 of the index number, and the second 2 is the number of characters
- The replacement character replace('replaced character ',' replaced character ') will only replace the first character;
var str='andyandy'; console.log(str.replace('a','b'));
//There is a string 'abcoefoxyozzopp' that requires the replacement of o with*
//There is a string 'abcoefoxyozzopp' that requires the replacement of o with* var str='abcoefoxyozzopp'; while(str.indexOf('o')!==-1){ str= str.replace('o','*'); } console.log(str);
- Convert character to array split('separator ')
var str2='red','green','blue'; console.log(str2.split(','));
- toUpperCase() / / convert to uppercase
- toLowerCase() / / convert to lowercase