Collected a bunch of questions you might be asked during an interview and presented the answers. Questions and answers will be updated continuously. Do not know whether the analysis is right or wrong, welcome everyone to correct, put forward suggestions.

JavaScript

Question: What is this?

Juejin. Cn/post / 696031…

Question: Understanding of prototype and prototype chain

zhuanlan.zhihu.com/p/62903507

Question: Typeof instanced of

  • Typeof returns a string type
  • typeofGenerally, only the following results can be returned:number“、”string“、”boolean“、”object“、”function” 和 “undefined
  • instanceofThe operator tests whether an object has a constructor in its stereotype chainprototypeProperties.
  • Instanceof is used to determine whether a variable is an instanceof an object

Question: The difference between call, apply and bind

All three are binding objects used to redefine this. The main differences are:

  1. Call and apply bind objects, while bind returns a new function that must be called to execute

  2. The call and bind parameters are placed directly, while the apply parameters must be placed in an array

  3. These three parameters do not qualify the type

    var person = {name:"jasen",age:99,}function myFun(){ console.log(`name:${this.name},age:${this.age}`); } myFun.call(person); myFun.apply(person); myFun.bind(person)(); // The new function must be called in order to execute: Name :jasen,age:99 Name :jasen,age:99 name:jasen,age:99 {} function myFun (FRM, w). The console log (` name: ${this. The name}, age: ${this. Age}, from ${FRM} to ${w} `); } myfun. call(person,' Beijing ',' xiamen '); Myfun. apply(person,[' Beijing ',' xiamen ']); Myfun.bind (person,' Beijing ',' xiamen ')(); myfun.bind (person,' Beijing ',' Xiamen ')(); Myfun.bind (person,[' Beijing ',' xiamen '])(); myfun.bind (person,[' Beijing ',' xiamen '])(); // Result Name: Jasen,age:99, from Beijing to Xiamen Name: Jasen,age:99, from Beijing to Xiamen Name: Jasen,age:99, from Beijing to Xiamen To undefinedCopy the code

EScript6

Q: How much do you know about the new ES6 features?

  • Answer: ES6 features class, Promise, async/await, arrow functions, generator

Question: What is the difference between the second parameter of then and catch in a promise? What are the three states?

  • A. promise B. promise C. promise D. promise
  • If the first function of then throws an exception, then the second function 5, class, throws an exception

Question: What are the solutions to callback hell?

  • Answer: 1. Through encapsulation module; 2, Use promise; 3, use await\async

Question: the generator

I don’t think I’ve used it at all

Q: How is ES6 compatible with ES3

Question: What is the difference between arrow functions and ordinary functions?

  • The first time answer: use quite simple
  • Second answer:

Node

Q: What is your understanding of the cycle of events?

  • A: Node is single-threaded. The main thread puts all the tasks in the loop queue, and then the underlying libuv library takes the tasks out of the loop queue and assigns them to different threads. The main thread also calls back at the same time, and the whole process forms an event loop

Question: How do you understand the tasks in the event queue

  • A: The main thread puts all the tasks in the event queue and divides them into micro tasks and macro tasks. Libuv library will take out the micro tasks for processing first, and then take out the macro tasks for processing after all the tasks are processed
  • Microtask: promise.next();
  • Macro task:

Question: Which native Modules of Node have you used?

  • A: Native modules: HTTP, STREAM, buffer, FS, PATH, child_process, Cluster, V8, OS, NET, etc
  • Familiarize yourself with what will naturally lead to further questions about principles

Problem: Buffer and Stream in Node module

  • The first time a: IT is seldom used in normal business scenarios, but I probably know that stream is a stream and data stream, which is used in reading large files and large data volume, similar to fragment reading. Buffer is a buffer, which is often used in conjunction with Steam
  • The second answer: Stream is a data stream. It is often used to read large files and large amounts of data. It avoids blocking threads when reading too much data at one time. A buffer is a buffer that can convert data to binary and then transfer data. It can solve the performance impact when a large amount of data is transmitted over the network in the form of strings.

Question: The difference between Express and KOA frameworks

  • Express and KOA

  • First answer: KOA is less used, Express has more mature middleware, koA is simpler

  • The second answer: are node server framework, this part of the framework is based on middleware to achieve, the main difference is the implementation of middleware.

    • Express packages and builds many middleware, such as Connect and Router, while KOA is lightweight and can be customized according to requirements
    • Express is based on callback to handle middleware, koA is based on await/async
    • Express does not execute middleware strictly according to the Onion model, whereas KOA executes middleware strictly according to the Onion model

Question: Is Node single-threaded?

Is a single thread, the main thread is a single thread, the bottom or multithreaded, compared to the implementation of the event loop is multithreaded, but although it is a single thread but also can support multithreading

Q: Node’s strengths and weaknesses?

  • Advantages: because it is single-threaded, there is no need to consider the problems caused by multi-threading deadlock problems, thread switching problems, multi-threading sharing problems.
  • Disadvantages: Since the hardware conditions are very good now, allocating multi-core servers to deploy Node applications will naturally cause a waste of resources. Single threads can also cause the entire service to exit if there is an error. A lot of CPU processing is prone to thread blocking