Interview Frequently Asked Interview Basic Level Knowledge Summary 3

Understanding of closures

Closure is a mechanism to protect private variables. It forms a private scope when the function is executed, and protects the private variables in the function from external interference. All that is said is to form a stack environment that is not destroyed.

Understanding the difference between small programs and ordinary APP embedded H5

The H5 in the applet and the APP is essentially loaded by webview, but the execution of the js code of the applet is realized through the underlying code based on the WeChat client, while the h5 page is directly executed by the browser to execute the parsed js file, so the small The data in the program is not suitable for storing too much data. When the data changes, frequent calls to the underlying js will affect the performance of the applet, and the applet will crash in severe cases.

New features of ES6

One difference between var /let/const.
Use var inside the function. When the function is executed, the variables in the function will be promoted to the top of the scope. The variables of var are global variables, and the variables declared by let and const are block-level variables. Variables declared by let and const will enter a temporary dead zone until the declaration of the variable is processed, and the variable declared by let can be copied again, and the variable declared by const must be initialized and assigned, and cannot be declared again in the same scope, and cannot be assigned again.
Two template literal backquote,
backquote template literal is essentially the literal of the embedded expression string,
before ES6, use the + sign to connect the string

例:
const name = '小明'
let message = name + ' please see '

Now use the backquote template

const name='xiao ming'
let message = `${
     
     name} please see`

The placeholder represented by ${expression}
Three destructuring
ES6 can use destructuring to extract values ​​from arrays and objects and assign them to unique variables.
Example

const point=[1,2,3];
const [a,b,c]=point;
console,log('a:'+a+' b:'+b+' c:'+c)
//输出a:1 b:2 c:3

You can also ignore value examples in destructuring assignment:

const point=[1,2,3];
const [a,b]=point;
console,log('a:'+a+' b:'+b)
//输出a:1 b:2

Structure assignment in the object

const game={
    
    
	name:'zu qiou',
	type:'qiu',
	isLike:'yes'
}
const {
    
    name,type,isLike}= game
console.log(name,type,isLike)
//输出 : zu qiou,qiu,yes

Four object literal abbreviation

let name='football'
let type='ball'
let isLike='yes'
const game={
    
    name,type,islike}
console.log(game)

Five spread operator...

//展开
const a=[1,2,3,4]
console.log(...a)
//合并数组
const a=[1,2,3]
const b=[4,5,6]
const c=[...a,...b]
console.log(c)
//输出:[1,2,3,4,5,6]

Six remaining parameters
Purpose 1 When
assigning an array, you can assign unquantified remaining parameters to a variable. Example

const color=['red','green','blue','yellow','black']
const [fcolor,scolor,tcolor,...itemcolor]=color

console.log(itemcolor)
//输出['yellow','black']

Use 2
Example of function receiving an indefinite number of parameters

function showColor(...color){
    
    
	let total = 0;  
 	for(const num of color) {
    
    
    	total += num;
 	}
  return total;
};

Advantages of arrow functions

1. Reduce the amount of code, simple and concise
2. Solve the pointing problem of this.
Ordinary functions point to the definite caller, and arrow functions point to the upper-level object that defines the function.

Common sorting methods for arrays

1. Sort method in
ascending order

var arr=[1,6,2,3,7,0]
arr.sort(a,b){
    
    
	return a-b;
}
console.log(arr)
//也可一行代码搞定
arr.sort()

Descending

var arr=[1,6,2,3,7,0]
arr.sort(a,b){
    
    
	return b-a;
}
console.log(arr)

Guess you like

Origin blog.csdn.net/qq_40969782/article/details/115218159