js basic knowledge points:
js is the front page interaction code (can do special effects, data interaction, data display, call API - application set Baidu Map Data Chart, etc.)
There are two ways for js to introduce web pages:
1. External introduction of <script src=""type="text/javascript"> (type can be omitted)
2. Direct Embedding in Web Pages: Upper Embedding and Lower Embedding (their different parsing order can slightly improve the performance of Web pages, initialize the page first)
Declaration of variables in JS (case-sensitive strictly in js)
Scopes of variables in js: global variables and local variables (do not declare variables var as global variables when declaring variables)
The keyword var for variable declaration
Declare a single variable: vara;
Declare multiple variables: var a, b;
Naming rules: hump nomenclature;
Variable data type: number string Boolean object null undefined
Method of detecting variable data type: type Of ();
For example:
Var b="nihao";
Console.log(typeof b);
The detected b is: string type;
Declarations of Functions in Js
Js is object-oriented
Function declaration keyword function
Declarations of simple functions:
function showname(){ }
Value Type Value Reference Type function Object -- Value Type is Value Reference Space Invariant Reference Type Reference Location is Variable
//Functions with Return Values function showinfo() { return '1'; } var a = showinfo(); console.log(a); //Parametric Function Formal Parametric function showname(name, sex, age) { return name; } var name = showname("Zhang San", "male", 18); console.log(name); //How to receive parameters if the function does not have a parameter list to pass parameters function showData() { //arguments parameter list object //arguments values are set to key:value index console.log(arguments[0], arguments[1], arguments.length); } showData("Floret", 18); //Anonymous functions with no function name are received by variables - anonymous functions are not declared in advance //List (); not a function error reporting var list = function () { console.log(arguments); return arguments[0]; } console.log(list(1, 2, 3)); //Function body of self-executing function // Return value with argument var mm = (function (x, y) { console.log(x, y); console.log(arguments); return x + y; })(1, 2); console.log(mm);
Closures in variables in js: Use other people's local variables (Closures will occupy a lot of memory, which will lead to memory leaks in Web pages, try to avoid using closures, which will store the value of closures in memory)
The local function is near:
function fooOuter2(){ var name="local"; function foo( ){ console.log(name);//Local local function is near } foo( ); } fooOuter2( );
Method rewriting:
var m=0; function f2(n){ temp=function (){ m+=n; } temp(); //Method rewriting The built-in method has its own function rewriting //tostring object String tostring override tostring automatically executes tostring in the String class f2.toString=function (){ console.log(1); return m; } return f2; } console.log(f2(1)(2)(3));
Operators in js: Operator logical operators comparison operators
Arithmetic Operator: + - */%+ -.
++ (Pre-budget + + or -- Operations before + + or -)
Logical Operator: &//!
Comparing Operator > < >= <=!=
Statements in Js: Loop Statement Conditional Statement switch Selection Structure Ternary Operations
Loop statement:
for( ; ; ){
}
While do while loop statement - do while execute at least once
Print a 9*9 multiplication table using the for loop:
for( var i=1;i<=9; i++){ for(var j=1;j<=I;j++){ document.write(i + "*" + k + "=" + ((i * k) < 10 ? (i * k) + " " : (i * k) + " ")); } document.write("<br>") }
Conditional statement:
If statement: if (condition){
}else{
}
Switch statement:
Switch (condition){
case :
break;
case :
break;
case :
break;
}
Ternary operations: expression one? Expressions 2: Expressions 3;
The first expression is true and the second expression is executed, otherwise the opposite is true.