Js data type

Basic data type: NULL undefined Number Boolean String Reference data type: Object New data type in ES6 symbol

Is NULL an object? Why is that?

Null is not an object. Typeof NULL outputs “object”, but this is just a bug in JS. In the original version of JS, the 32-bit system was used to store the type information of a variable in a low level for performance reasons, starting with 000 means that the object is null

Methods to detect arrays

  • typeof

Checking an array returns “object”, so you cannot use Typeof to check an array

Var arr= [1,2,3,4] typeof arr//"object"Copy the code
  • instanceof

The prototype operator is used to check whether the constructor’s prototype property appears on the prototype chain of an instance object

Var arr= [1,2,3,4] arr instanceof Array //trueCopy the code
  • Array.isArray()

ECMAScript adds the array.isarray () method, which is used to finally determine whether a value is an Array, regardless of the global execution environment in which it was created.

Var arr= [1,2,3,4] array. isArray (arr) //trueCopy the code
  • Object.prototype.toString
function isArray(arr) {
  return Object.prototype.toString.call(arr) === '[object Array]'
}
Copy the code

What is a closure?

The Little Red Book 3rd Edition P178 Defines closures: A closure is a function that has access to a variable in the scope of another function. (Arguments are arguments that are used in a function, but are neither function arguments nor local variables to the function.)

What are the common types of Content-type?

Text /plain Text type Text/CSS CSS type Text/HTML HTML type Application/X-javascript JS Application/json json type image/PNG JPG GIF image / * (/. +. (PNG | JPG | GIF) $/. The test (pathname) matched to the pictures

The difference between anti-shake and throttling

Debounce means that a function can only be executed once within n seconds after an event is triggered. If an event is triggered again within n seconds, the function execution time is recalculated. Throttling refers to firing events continuously but executing functions only once in n seconds. Throttling dilutes the execution frequency of the function.

Modularity difference

Correctly match 11 digits

/^1\d{10}$/ ^ begins \d is the number 10 for 10 bits

The HTTP status code

category why
1xx Informational (Informational status code) The accepted request is being processed
2xx Success (Success Status code) The request is successfully processed
3xx Redirection (Redirection status code) Additional action is required to complete the request
4xx Client Error (Client Error status code) The server cannot process the request
5xx Server Error The server failed to process the request
1) 2XX — indicates that the request was processed normally
Status code why
—- —-
200 ok Request Processing Normal
204 No Content The request was processed successfully, but no resources can be returned to the client
206 Partial Content Is a request for a portion of a resource
2) 3xx– indicates that the browser needs to perform some special processing to properly handle the request
Status code why
—- —-
301 The URL of the resource has been updated. Permanent redirection
302 The URI of the resource has been temporarily located elsewhere. Temporary redirection

3) 4XX — indicates that the client is the cause of the error

Status code why
400 Bad Request The server could not understand the request sent by the client
401 Unauthorized The status code indicates that the request to be sent requires the AUTHENTICATION information that passes the HTTP authentication (BASIC authentication, DIGEST authentication).
403 Forbidden Access to that resource is not allowed
404 Not Found There is no requested resource on the server
4)5XX — The server itself has an error
Status code why
—- —-
500 Internal Server Error This status code indicates that an error occurred on the server side while executing the request
503 Service Unavailable This status code indicates that the server is temporarily overloaded or is down for maintenance and cannot process requests at this time

Array to heavy

Segmentfault.com/a/119000001… www.zhihu.com/

Rearrange and redraw

Repaint or Redraw: Once the box position, size, and other properties, such as color and font size, have been determined, the browser paints the original colors according to their characteristics and renders the content on the page. Redraw is the behavior of the browser triggered by a change in the appearance of an element. The browser redraws the element based on its new attributes to give it a new appearance.

Conditions that trigger a redraw: changes the appearance attributes of an element. Color = background-color


Rearrangement (refactoring /reflow /reflow) : When part (or all) of the render tree needs to be rebuilt due to changes in the size, layout, hiding, etc., this is called reflow. Each page needs to be refluxed at least once, the first time the page loads.

The relationship between redraw and rearrangement: During backflow, the browser invalidates the affected part of the render tree and reconstructs that part of the render tree. When backflow is complete, the browser redraws the affected part to the screen. This process is called redraw.

Rearrangement always leads to redrawing, but redrawing does not necessarily lead to rearrangement.

Pseudo classes and pseudo elements

Pseudo class: pseudo class is equivalent to a state switch, which needs to be triggered manually. When the switch is triggered, the element style is modified to achieve a special dynamic effect. Pseudo class: Link :hover

Pseudo-classes: “ghost” categories that exist in A DOM document (no label, not found, only visible when triggered) and exist logically but do not need to be identified in the document tree.

Pseudo-element: pseudo-element can be compared to a fake element, but does not exist in the DOM tree. It is usually used to add small ICONS to the element, remove floating effects, etc. :before ::after Pseudo-element: does not exist in the DOM document, is a virtual element, is to create a new element. This new element (pseudo-element) is a child of an element that exists logically but does not actually exist in the document tree.

The root of pseudo-classes and pseudo-elements: whether or not a new element is created, the newly created element is called “pseudo-no element”.