Summary of Javascript interview questions

About the difference between get and post

  • The difference between get and post are two request methods around the http protocol, get is generally used to obtain data, and post is generally used to transmit data
  • Get is more insecure than post. The parameters of get are directly exposed on the URL, so the parameters are visible, so they will not be used to transmit sensitive data. Of course, compared to post, the data transmitted by get is faster than post. faster
  • The maximum data size of get transfer is limited (8KB) ​​and post is unlimited (streaming/slicing)
  • Get is harmless when the browser rolls back (it will not send a request to the server), and post will send a request (when returning to the previous page). It is common to return to the previous page after the network is disconnected and the post can be displayed normally.
  • Get can only perform url encoding (urlencode) when sending a request, while post has multiple encoding methods (request headers)

The difference between var/let and const


var and let, const are const declared constants that appear in ES5 and ES6 respectively must be declared

  • Once declared, must be assigned,
  • Cannot be modified after declaration
  • If the declaration is a composite type of data, its properties can be modified, but if the declaration is an object, its properties can be modified (no error will be reported). The reason why no error will be reported: it involves the stack memory of the heap memory, that is, changing obj When the attribute is changed, the value of the heap memory corresponding to the object of obj (the change is not the address of the heap memory but the value of the corresponding data in the changed heap memory address)

let and var declare variables, which can be changed after declaration, and can be declared without assignment (const must be assigned).
var allows repeated declarations, but later assignments will overwrite previous assignments. let and const are not allowed in the agreed scope Repeat the declaration, otherwise an error will be reported.
The variable declared by var has declaration promotion (the variable will be promoted to the top of the scope when the script is running)), that is, the declaration promotion of the variable (the one above)

Var does not have block-level scope, while let and const have the concept of block-level scope.
Even if let and const are declared globally, they are not values ​​in the global scope.

About scope in ES5 and ES6

  • ES5: global scope, cross-level scope is included by {}, {} in if statement and for loop
  • ES6: Accounting scope is added in ES6, block-level scope is wrapped by {}, and {} in if and for statements also belongs to block-level scope

HTTP request status code (common)

  • 200: The request was successful
  • 301: Request resources such as web pages are permanently transferred to other URLs
  • 302: The resource is the same as above but just moved to another URL for snacks
  • 304: Unmodified, the requested modification has not been modified. When the server returns this status code, it will not return any resources. The client usually caches the accessed resources
  • 404: The requested resource, such as a web page, does not exist
  • 502: There is an error on the server side. Generally, this error is a problem with the backend, and it is none of your business.

Write a function to get any term of the Fibonacci sequence

  • The value of the first item and the second item is 1, and the value of each item starting from the third bit is the sum of the first two items
//  递归求斐波那契数列
// 要求h传入的值为我需要的第几项的值
function fib(h) {
    
    
	// 如果传入值为1或者为2就返回1
	if (h == 1 || h == 2) {
    
    
		// console.log(111);
		return 1;
	}
	// 递归:函数自己调用自己
	// 任意一项的值时前两项相加的和
	return fib(h - 1) + fib(h - 2);
}
fib(5);

Execution order of different scopes of timers

Timers in the global scope

The following topics

for (var i = 0; i < 3; i++) {
    
    
	setTimeout(() => {
    
    
		console.log(i);
	}, 0);
	console.log(i);
}

We can see that there are timers and loops, but we can understand general timers, but some of our friends are confused when the execution timing is 0. How should we execute this?
Answer: In fact, it is the same as regular execution,
we can split it up

var i = 0;
setTimeout(() => {
    
    
	console.log(i);
}, 0);
console.log(i);
i++;
setTimeout(() => {
    
    
	console.log(i);
}, 0);
console.log(i);
i++;
setTimeout(() => {
    
    
	console.log(i);
}, 0);
console.log(i);
i++;

In fact, it's obvious now
insert image description here

Timers in block scope

Next we will upgrade it, we change the var declaration to let declaration, what will happen to the result?

for (let i = 0; i < 3; i++) {
    
    
	setTimeout(() => {
    
    
		console.log(i);
	}, 0);
	console.log(i);
}

A simple understanding of the block-level scope execution logic is
insert image description here
that a block-level scope will be generated every time the loop is executed, and then there are prints and timers under the block-level scope. In the order of execution, the main program will be executed first, and then To execute the timer, because of block-level scope, all timers find the above statement through the scope chain, so the execution order is
insert image description here

git common commands

Here we only talk about the basic format, it’s too detailed, okay? It's not good (mostly lazy)

local warehouse

  • Initialize warehouse
	git init
  • Temporary storage
	git add 文件名
	// 或者
	git add
  • Staging version
 git commit -m '版本描述'
  • the branch
 git branch
  • merge
 git merge

remote warehouse

  • clone
 git clone
  • renew
 git pull
  • upload (push code)
 git branch

Guess you like

Origin blog.csdn.net/weixin_50112395/article/details/127351702