If the posture is not correct, get up and learn to find your own track. Deep ploughing becomes a scarce resource to do differentiated competition
preface
Every Year in March and April in the recruitment season, technical problems can be cramming, while now to consolidate their foundation, often see the interview high-frequency questions, you can have confidence in the interview, the following I will give a basic series of interviews, I hope everyone can harvest their ideal offer!
Question and answer session
Constructor vs. class
1. Constructor (prototype) can be enumerated, class (prototype) can not be called with the new keyword, and class (new) can only be called with 3. The key difference is that a subclass creates the parent execution context first, modifies this in the subclass contructor, and modifies this in the subclass contructor, while the constructor creates the instance execution context and combines the constructor properties and methods under the prototypeCopy the code
The difference between arrow functions and ordinary functions
1.The arrow function does not havearguments
2.The arrow function does not have Contructor and therefore cannot be usednewKeyword call3.Arrow functionthisPointers are created at declaration time and point to the execution context of the parent, as opposed to normal functionsthisPointing is determined at execution time4.The arrow function cannot be usedyield
Copy the code
Why can ‘string’ call the API under string
We know that properties and methods are only available to objects, but literal strings can use apis like repeat. The reason for this is that javascript is boxed and unboxed. When 'string' calls the API, Javascript internally generates an implicit String (boxing), calls the corresponding API to return the result, and finally deletes the String (unboxing)Copy the code
Why use void0 instead of undefined
The reason is that undefined can be used as a variable. In IE8 and below, undefined can be assigned, void evaluates the following expression, and 0 is the least time-consumingCopy the code
What apis does Primose have
1. All wraps all the expressions in the array under promise.resolve, Resolved when all Promise states are resolved, all data will be collected via then. Disadvantage: Resolve will not be used when there is a reject state. But the remaining element expressions do not interrupt the disadvantage: Race cannot resolve or reject, and will return a Promise state change. AllSettled compares the state of an expression to a first function, which would return all data and state to the first function. Promise resolved will return when the first Promise is resolved. If the Promise is rejected, it will return reject or catchCopy the code
The scope chain
Javascript does some preparatory work when executing code, and the preparatory work is to create an execution context, which consists of three parts: 1. Variable object 2.this points to 3. scope chain execution context management: The execution context is managed by the execution context stack the first time we run javascript code, we generate a global execution context, and we push it into the execution context stack and once we know the execution context, We know that javascript is a lexical scope, and the scope of a function is created when the function is declared. Here's how: Var a = 1 function foo() {console.log(a)} foo() {console.log(a)} foo() {console.log(a)} foo(); Instead, the execution context is created first: 1. The [[Scope]] of the assignment function initializes the current Scope chain. 2. Create an active object (AO) based on arguments. Push the active object into the scope chain created in the first step {AO, active object VO, parent variable object} and here you have a chain of scopes for the current execution context 4. This is then initialized from the current calling object to 5. The function execution context is pushed onto the execution context stack 6. After the function completes execution, the AO object is eliminated and the execution context is popped upCopy the code
SetInterval disadvantages
The setInterval function is a built-in function of the Window and is often used for timers. However, it has one drawback: setInterval's callback function is not executed immediately after the timer expires. Instead, it is pushed into a task queue. This can cause the timer to not execute at the actual time interval, Function setIntervalSimute(callback) {setTimeout(() => {callback() setIntervalSimute(callback) }, waitTime) }Copy the code