1. Array (object, string) methods (must be memorized)

  • Push, to one or more elements at the end of the array, and return the new length of the array;
  • Pop, deletes the last element of the array. The deleted element is returned as a return value.
  • Unshift to add one or more elements to the beginning of the array and return the array’s new length;
  • Shift removes the first element of the array. The deleted element is returned as the return value.
  • Splice, which removes one or more elements from the array and can add new elements at the same location. The deleted element is returned as a return value.
  • Concat, which combines multiple arrays and returns a new array;
  • IndexOf, which returns the first occurrence of the top element in the array;
  • ForEach, which takes a function as an argument, iterates through the array without stopping.

2. Array deduplicate (appropriate back a few, will ask)

  • Double loop
  • IndexOf and includes
  • Order to heavy
  • The Filter method
  • Key/value
  • Set and map of Es6

3. What is the difference between Localstorage, session and Cookie? (Need to recite, but did not ask)

  • Localstorage and sessionStorage localstorage. The localstorage will not be destroyed after the browser is closed and must be destroyed manually. The sessionStorage will be destroyed after the browser is closed.
  • Cookies are usually generated by the server. You can set the expiration time. If cookies are generated by the browser, they become invalid by default. The average data store size is 4KB and is carried in HTTP headers each time. Storing too much data can cause performance problems.

 

4. Rearrange and redraw (memorize)

  • Rearranging means that part of the render tree (or the entire render tree) needs to be reanalyzed and node sizes recalculated;
  • Redraw is when a part of the screen needs to be updated when the geometry of the node changes or when the style changes, such as changing the background color of an element.

 

5. Tremble and throttling (must be carried)

  • The stabilization function controls the number of times a function is executed within a certain period of time. Anti-shaking means that the function is executed only once (for the last time) within N seconds, and if it is fired again within N seconds, the delay time is recalculated.
  • Throttling function specifies a unit time, in this unit time can be triggered at most once function execution, if the unit time of multiple triggered function, only one effective.

 

6. Prototypes and prototype chains

Each function occasionally has a prototype property. This property points to an object, the prototype of the instance created by calling the constructor, which can be accessed via the _proto_ of the instance object. When an instance is created, it is associated with stereotypes by default and inherits properties from them. Each stereotype object has a constructor property that points to the associated constructor; If the properties of an instance Object are not accessed, the JS engine will look in the prototype Object, in the prototype of the prototype, all the way to Object.

7. Js inheritance (six and familiar)

  • Prototype chain inheritance
  • Inherit from the constructor
  • Combination of inheritance
  • Original type inheritance
  • Parasitic inheritance
  • Parasitic combinatorial inheritance

8. How to optimize page loading speed? (Must recite well, can be done in the project)

  • To optimize the image
  • Use the CDN
  • Reduce DNS lookups
  • Simplify JS and CSS code
  • Compression components
  • Lazy loading
  • Reduce HTTP requests
  • Avoid redirection
  • Delete duplicate scripts
  • Use the browser cache

9. Cross-domain problems (must be memorized)

  • Same-origin Policy Restriction
    • Cookies, localStorage, and indexDB cannot be read
    • The DOM and JS objects cannot be obtained
    • The Ajax request could not be sent
  • The solution
    • The json cross-domain
      • Only get cross-domains can be solved
      • Principle: The SRC attribute of a script tag is not restricted by the same origin policy. All SRC and href attributes are not subject to the same origin policy. Third-party server data content can be requested.
    • Sharing CORS across resources
      • How it works: After the server sets the access-control-allow-OriginHTTP response header, browsers will Allow cross-domain requests
      • Limitations: Browsers need to support HTML5, can support POST, PUT and compatible with IE9 or above.
    • The Node agent is cross-domain
    • Nignx cross-domain

10. What are the methods of Js to determine the data type? (To memorize, simple)

  • The Typeof operator
  • Instanceof
  • Object. The prototype. ToString. Call (XXX) method

11. The role of New (not asked)

  • Creates a new object in memory
  • Inside this new object[[prototype]]The property is assigned to the constructor’s Prototype property
  • This inside the constructor is assigned to this new object (that is, this refers to the new object)
  • Execute code inside the constructor (adding properties to the new object)
  • If the constructor returns a non-empty object, the object is returned; Otherwise, the newly created object is returned.

12. This point (back, asked many times)

  • This always points to the direct caller of the function;
  • If you have the new keyword, point to the object that comes out of the new
  • In the event, this refers to the object that triggered the event, and this in Ie’s Attachevent refers to the window

13. Display: None and visiblity: hidden

  • Display: none; – rendering does not take up space, causing poor rearrangement performance
  • Visbility: hidden; Will render hidden space, cause high redraw performance, will quilt element inheritance.

14. Closure (must back, not to see the Silicon Valley JS advanced)

A closure occurs when a nested inner function references a variable of an outer function. Closures are nested internal functions. Function: allows the internal variables of a function to remain in memory after execution, allowing external manipulation of the internal variables of the function.

15. What is DOM? (Need to know)

  • DOM: Document, Object, Model Document Object Model;
  • Javascript uses the DOM to manipulate HTML documents.