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!

The issue of

Javascript Interview Guide part 1

Question and answer session

Principle of Async Await

Advantages of Async and Await over Promise: - Syntax concise and clear, save a lot of unnecessary anonymous functions - directly use try... catch... Exception handling - add conditional judgments more intuitive - reduce unnecessary intermediate variables - more clear error stack - easy to add breakpoints to each asynchronous call Async as an improved version of Promise, used in each asynchronous function, Understanding the principle of Async Aawit allows us to control the details of the code so we can go into the principle of Async Aawit and see how it is actually implemented, look at the following codeCopy the code

Basic principle of

  function *getStep() {
    yield Promise.resolve().then(() => {
      console.log('resolved')
    })
    console.log('value');
    yield Promise.reject(2)
    console.log('reject');
    throw 3
  }

  function ASomeWeAsync() {
    return new Promise((resolve, reject) => {
      const step = getStep()
      let next = void 0
      function callback(nextF) {
        try {
          next = nextF()
        } catch(err) {
          return reject(err)
        }

        if (next.done) {
          return resolve(next.value)
        }

        Promise.resolve(next.value).then(() => {
          callback(function() {
            return step.next()
          })
        }, () => {
          callback(function() {
            return step.throw()
          })
        })
      }

      callback(function() {
        return step.next()
      })
    })
  }
  
  ASomeWeAsync()
Copy the code

To observe the

The result of the above code execution 1. Resolved to print before value 2. 'Resolved' and 'value' will be printed, not 'rejected'Copy the code

conclusion

Async await is essentially a synchronous logic implemented using the Generator of ES6. Async await does not proceed when encountering a reject PromiseCopy the code

Why is getBoundingClientRect a function?

GetBoundingClientRect can get information about the DOM element's distance from the viewport and the size of the DOM element itself by using properties such as offsetX/clientX, Why is getBoundingClientRect a function? GetBoundingClientRect uses the function for compatibility because the default coordinates start at (2, 2) when IE retrieves distance informationCopy the code

Who is bigger, math.max or math.min?

When comparing the size of two values, we usually use two built-in functions, math.max and math.min. Which one is larger? Math.max is used to compare who is bigger, so the comparison has a reference dependency. When we pass in a parameter, we return the same parameter, indicating that the reference dependency is smaller than this number. How can we guarantee that all numbers are larger than this reference dependency? Min returns Infinity only if the reference dependency is minimum (-infinity) and math.min is greater than math.maxCopy the code

Memory leaks and memory overflows

We usually for more than two nouns have an inkling of the border, think both is to express the same meaning, but actually there is a difference between memory: memory allocation under a Tab space is limited, when we fill the memory space, can appear out of memory problem, the program will be an error, unable to continue and close the memory leaks: When a program is applying for memory, it does not release the original memory space in time. As a result, the memory space applied for by subsequent programs becomes narrow, which eventually leads to memory overflow. This means that the current running space of the program is far less than the requested spaceCopy the code

What are the arguments to the setTimeout callback?

setTimeout(function(. arg) {
  console.log(arg)
}, waitTime)
Copy the code
The setTimeou function normally passes only two arguments: callback. WaitTime setTimeout can pass an infinite number of arguments, starting with the third argument and passing them as arguments to the callback functionCopy the code

scrollBy

ScrollTo is what we usually use as a calling function and scrollTo is set based on the entire scrollable area of the scrollbar so if we want to go to 200px we pass in 200, which is an absolute value scrollBy as opposed to scrollTo, It's a relative value so if we're at 200px and we want to jump to 300px scrollBy(100) and scrollTo needs scrollTo(300) and scrollBy helps us move the position without having to figure out what position it is right now, okayCopy the code

a === 1 && a === 2 && a === 3

How do you achieve this? Answers can be found on js1Copy the code

Pay attention to the public number, daily update

Public account: Front-end Martin

Wx number: IAmFineThanksMartin