1. What about JS data types? The difference between basic and quote? Symbol and Bigint, what are the application scenarios?

Basic types: null, and undefined, string, object, Boolean, symbol, bigint

Reference types: object,object includes: object,array,function

Difference: Basic types are stored in stacks and can be accessed directly; Reference types are objects stored in memory;

Symbol: SYMBOL is a new data type added in ES6. It is essentially a unique identifier that can be used as a unique attribute name for an object so that no one else can overwrite or overwrite the attribute value you set

Bigint: The Bigint data type provides a way to represent integers greater than 2^53-1. BigInt can represent an arbitrarily large integer

2. How to judge the data type? Instanceof principles? Determine an empty object?

Basic type: typeof; Citation type: instanseOf; Can judge: Object. The property. The tostring. Call ();

The Instanceof principle: follow the prototype chain from the current reference proto level by level to find the corresponding prototype. Returns true if found.

Keys ();

Var /let/const Temporary dead zone?

Var: function scope, no block concept, can be accessed across blocks, not functions

Let: block-level scope, which can only be accessed within the block scope, not across blocks or functions

Const: block-level scope, must be initialized (that is, must be assigned) when used, can only be accessed in the block scope and cannot be modified

Temporary dead zone: A variable is unavailable in code express until it is declared using the let command

4. Tell me your understanding of functional programming.

The purpose of functional programming is to use functions to abstract the flow of control and operations acting on data, thereby eliminating side effects and reducing changes to state in the system. (Any execution is the same, no side effects)

5. The meaning and application scenarios of anti-shake and throttling? Write it out?

Frequent function calls add a limit and reduce frequency

Buffeting: When a function is called continuously, the function is not executed. It is called only after a certain amount of time has passed since it has all been stopped

function debounce(){
    let timeout;
    return function(){
        let arg=arguments;
        let that=this;
         clearTimeout(timeout); ! timeout && fn.apply(that, arg); timeout=setTimeout(() = > {
            timeout = null; }, wait); }}Copy the code

Throttling: Set the time to respond only once in a period of time

function throttle(fn, wait) {
  let timeout; 
  return function () {
    if(! timeout) { timeout =setTimeout(() = > {
        timeout = null;
        fn.apply(this.arguments)
      }, wait)
    }
  }
}

Copy the code

Usage scenario: Real-time search function for input box

6. What is the difference between call, apply, and bind? The bind? Can you change this after bind? Why is that?

You can modify the function’s this pointer

Call: Parameters are passed in sequence and called immediately;

Apply: The second argument is an array, called immediately;

Bind: Parameters are passed in sequence to return the corresponding function for later call;

7. Closure concept, the most important question is the closure scenario?

Function scope returns a function, and returns the function used by the function variable; Simulating private variables

8. Using ES5 to implement ES6 class inheritance? There are a lot of inheritance questions

9. Deep copy vs. shallow copy? Common methods? Write a deep copy function?

Shallow copy: Creates an object that has an exact copy of the original property value, the base type is copied with the base type value, and the reference is copied with the memory address.

  • object.agsign();
  • Lodash _clone ();
  • Expansion operator… ;
  • Array.prototype.concat();

Deep copy: To copy an object completely out of memory, creating a new memory location to store it, and the reference of the new object does not affect the original object.

  • Json.stringify (json.parser ()), disadvantages: cannot copy functions (null) and re ({});
  • Lodash _cloneDeep ();
  • Hand traversal implementation

10. What JavaScript design patterns do you know? What’s the difference between an observer and a publish subscription?

Singleton, Policy, Broker, Decorator (VUE), publish-subscribe;

11. Tell me about your understanding of asynchronous JavaScript programming.

Callback is nested layer by layer; promise; async,awiat;

What is the difference between ES Module and CommonJS Module? The way they load each other? It’s usually AMD

AMD: rely on front-loading, pre-loading

CMD: Advocate relying on proximity and deferring execution

CommonJS features:

All code runs in the module scope and does not pollute the global scope;

The module is synchronously loaded, that is, only after the loading is complete, the following operations can be performed;

The module is cached after the first execution, and only returns cached results if it is reloaded. If it wants to execute again, the cache can be cleared.

ES6 Module features (compare CommonJS)

CommonJS Module is loaded at runtime, ES6 Module is output at compile time; CommonJS loads the entire Module and loads all interfaces in it. ES6 Module can load one interface separately. CommonJS output is a copy of a value, ES6 Module output is a reference to the value, the output Module internal changes will affect the reference change; CommonJS this refers to the current Module, ES6 Module this refers to undefined;

ES6 Module is not compatible with browser, export/import used in webpack is packaged as exports/require.

13. Promise. All, Race, allSettled concept? A lot of handwriting problems, like using promise to limit the number of concurrent requests, right?

Promise.race(iterable): Looking at the first fastest, the method returns a Promise that will be resolved or rejected once a Promise in the iterator is resolved or rejected.

Promise. All: success is success, there is a failure, failure; Returns the result of the first failure;

Promise.allSettled: All results return;

14. Object oriented, function oriented

Object-oriented: To perform certain actions against objects, which can be customized to extend; Three major features: encapsulation, inheritance, polymorphism

Process-oriented: Define many actions and specify who should perform the actions;

15.node

Is a V8 engine based javascript runtime;

16. What’s the difference between interface and type in typescript?

Type generates a new alias for the type.

The interface defines a specific set of objects.