JavaScript study notes - Fundamentals

White whore address: https: //www.bilibili.com/video/BV1HJ41147DG

This notebook is not fully documented study notes, only records of their strange feeling or feeling important part

To study recommended materials + B station white whore

A full set of courseware Information Address: Link: https://pan.baidu.com/s/1N6iJGPMkPLBkY9x7SMZbXA extraction code: 8fil 

 

JS 
Three formats:
Inline   
Line (onclick =) 
Outreach <script src = "my.js"> This intermediate code can write </ script>
JS string convention single quotes
Note 
Single line // 
Multiple row / multiple rows * * / shift + alt + a
Weakly typed language: no data type of the variable

Pop (acquisition)
1, var myname = prompt ( 'Enter your name'); // Get user interaction to take data string type
2、alert(myname)
3, console.log () // printed to the console

Not only evaluate reference variable declaration would cause such actual coding of global variables do not advocate for our security but may be of some use to test
Variables are case sensitive

Variables octal leading zero hexadecimal 0x
isNaN () judgment is not a function of the digital
String concatenation str1 + str2
true+1=2
undefined+1=NaN

Arithmetic data types can be implicitly converted to numeric rounding the integer part function is taken directly, without rounding

Arithmetic logic interrupt short circuit can affect the operation of the program priority &&> ||>!
He && Logical operator: if in the process non-Boolean value appears, the foregoing is true returns false return to the previous value preceding the value of the latter
console.log(123&&456) //456
console.log (0 && 456) // 0 count those fake it? : 0 '' NaN undefined
console.log (0 && 456 + 2 && 3 * 4) // 0 0 or 0 since the short circuit across the back of the calculations are not directly returns 0
He || logical operator: if in the process non-Boolean value appears, the foregoing is true return to the previous value preceding it is false is returned following values
console.log (0 || 456) // 456 first false returns the second
console.log (123 || 456) // 123 first returns a true first

function return value of the function in the final can only be the last one no matter how much return value to return multiple values ​​can be packed into an array output

Global variable (defined outside the function) and a local variable (the function definition)
Scope chain : internal functions to access external variables function, go first to take its own internal, to find their own internal do not include your own external functions, in the absence of keep looking outwards


Pre-analysis:
JS engine will function and scope of the current var raised to the top of the current scope of execution
Pre-analytical variables (variables upgrade):
The role of the current domain variable declaration raised to the top of the current scope to perform, but only to enhance the operating statement, does not raise assignment
Pre-analytic function (function upgrade):
The current scope function declarations raised to the top of the current scope of execution, but does not call functions

Object:
A set of data, through the internal dictionary "key-value pair" is similar to the data stored python function definition is only a little different objects inside
sayHi:function(){
alert(1)}
Take advantage of the object to store data:
Each data object has an internal storage "button" pointing object is identified, the developer is more intuitive to use the object directly obtain accurate data, clear data storage structure
Another use new Object () methods to create objects feel like better

Constructor: object inside some of the same properties and methods which abstract and encapsulated into Java function has no return value as constructors
Constructor function name () {
	. This attribute = value; 
	this. Method = function () {} 
}
var zz = new constructor function name (parameter plus, plus parameters)

Traverse the object property output
for(var k in obj){
console.log(k)
console.log(obj[k])
}

Built-in objects: JS native language objects for developers to directly use common Math Date Array String
Math.round () rounding method
Math.random () random decimal between 0 and 1
Date constructor needs to instantiate a built-in function with respect to time

instanceof to detect whether the array
was arr = []
console.log(arr instanceof  Array)
There is a method arr.isArray () H5 new ie9 more support

sort () to sort only came a bit if need tens digit
was arr = [1,13,22,6,8]
arr.sort(function(a,b){
	return ab; // ascending order of arrangement
	return ba; // descending order
})

indexOf () array to find whether there is any element of the array subscript did not return -1  
This function can be used function to the array configured weight
function unique(arr) {
            was newArr = [];
            for (var i = 0; i < arr.length; i++) {
                if (newArr.indexOf(arr[i]) === -1) {
                    newArr.push(arr[i]);
                }
            }
            return newArr;
        }
        // var demo = unique(['c', 'a', 'z', 'a', 'x', 'a', 'x', 'c', 'b'])
        var demo = unique(['blue', 'green', 'blue'])
        console.log(demo);

Array to a string tostring () join () 
        // 1. toString () to convert our array to a string
        was arr = [1, 2, 3];
        console.log(arr.toString()); // 1,2,3
        // 2. join (separator) 
        was Arr1 = [ 'green', 'blue', 'pink'];
        console.log(arr1.join()); // green,blue,pink
        console.log(arr1.join('-')); // green-blue-pink
        console.log(arr1.join('&')); // green&blue&pink


 //   determine the highest number of characters in a string appears 'abcoefoxyozzopp' in, and count the number of times it.
 // This algorithm comparing clever clip
        // o = 1
        // o.b = 1
        // o.c = 1
        // oo = 4
        // core algorithms: the use of charAt () to traverse the string
        // each character is stored to the object, if the object does not have this property, it is 1, then if there is a +1
        // traverse the object, to get the maximum value and the character
        was str = 'abcoefoxyozzopp';
        There o = {};
        for (var i = 0; i < str.length; i++) {
            var chars = str.charAt (i); // chars each character of the string is
            if (o [chars]) {// o [chars] attribute value is obtained
                o [chars] ++;
            } else {
                o [chars] = 1;
            }
        }
        console.log (d);

 

Guess you like

Origin www.cnblogs.com/Qiuzhiyu/p/12619288.html