2021 front end interview questions – JS


1. Prototype

2021 front end interview questions - JS

2. Prototype chain


When finding an attribute of an object, you will first find it from its own attribute,

If you can’t find it, you’ll get it from it_ proto_ Property is the prototype property of the constructor,

If it hasn’t been found, it will continue to be there_ proto_ Search up to the top level. If it cannot be found, it is undefined,

Layer by layer like this is called prototype chain


3. New keyword

New is a function. What happens in the middle

1. Open up a memory space, that is, create an empty object, obj = {} or obj = new object ()

2. Add this new object_ proto_ Property points to the prototype of its constructor

3. Bind the constructor this as the new object, and hang the property and method (call or apply) on the empty object

4. Return this new object

4. call apply bind

Same: change the function context this point

Difference: bind returns a function and will not be executed immediately

The second parameter of apply is in the form of array

Call apply is a direct call to a function

5. Implementation of call apply bind

6. The direction of this

1. Call directly as a normal function, and this points to window

2. If it is called as an object method, this points to the object that calls it

3. The arrow function does not have this. This depends on the this of the non arrow function closest to it

4. This of the constructor points to the instance object that creates this constructor

7. Scope

1. Lexical scope (static scope)

JS uses lexical scope

Only functions can be scoped

Functions allow functions to access variables in the outer scope

When a function is defined, it determines the scope of the function. Lexical scope concerns where the function is defined

2. Dynamic scope

When a function is called, it determines the scope of the function. The dynamic scope cares where the function is called

8. Scope chain

The value of a variable will be found in the scope of the function that created the variable. If it is not found, it will be searched upward until the global scope is found, which forms a scope chain

9. Throttling and anti shake

1. Throttling

2. Anti shake

10. Inheritance (6 ways) and advantages and disadvantages

1. Prototype chain inheritance

2. Constructor inheritance

3. Composite inheritance (prototype chain inheritance + constructor inheritance)

4. Prototype inheritance

5. Parasitic inheritance

6. Combinatorial parasitic inheritance

11. Closure

A function defined inside a function that has access to variables in the scope of an external function



12. promise

13. JS event loop

JS tasks in operation have a special mechanism for collection, queuing and execution. This mechanism is event loop

When encountering synchronous events, it is executed directly. When encountering asynchronous events, it is divided into macro tasks and micro tasks

If there are tasks in the micro task list, execute the micro task first and then the macro task

14. es6 let/const

Can the block level scope {temporary deadband} be modified

15. Axios (interceptor)

16. Arrow function

It is invalid to modify this without this} call apply method

No prototype attribute

No argument

Cannot use new , cannot be used as a constructor, and an error will be reported

17. ES6 class syntax

18. Implementation of instanceof

19. ES6 set and map

Continuously updated

Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters:https://www.cnblogs.com/xiegongzi/p/15782921.html Link to component development:https://www.cnblogs.com/xiegongzi/p/15823605.html 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]