1. What is the difference between functional components and class components?

  1. State cannot be used, nor can the component’s lifecycle methods be used.
  2. Receiving Props, rendering DOM, and this determines that the function components are presentable components and not concerned with other logic.
  3. There is no this
  4. Performance is the same

Blog.csdn.net/xuchaobei12…

2.refs

  • react

    Refs provides a way to access DOM nodes or React elements created in the Render method

  • vue

Ref is used to register reference information for an element or child component. The reference information will be registered with the parent component’s $refs object. If used on a normal DOM element, the reference refers to the DOM element. If used on a child component, the reference refers to the component instance

3. The ts generics

Definition: Data types that are not defined in advance. The specific type is determined at the time of use.

Benefits:

  1. Functions and classes can easily support multiple types, increasing the extensibility of programs.
  2. No need to write multiple function overloading, lengthy joint type declaration, enhance code readability.
  3. Flexible control of constraints between types.
  • Generic functions:
Function log<T> (value:T):T{console.log(value); return value; } / / call log < string > [] ([' a ', 'b']) log ([' a ', 'b']) / / use the type alias Define the type of a generic function type Log = < T > (value: T) = > T let myLog: Log = Log;Copy the code
  • Generic interfaces:
interface Log <T> {
    (value:T):T
}
let myLog:Log=log;
myLog('1');
Copy the code
  • A generic class:

// A generic class cannot constrain its static member static

class Log<T>{
    run(value:T){
        console.log(value);
        return value;
    }
}

let log1 = new Log<number>()
log1.run(1);
let log2 = new Log();
log2.run('1');

interface length{
    length:number
}

function log<T extends Length>(value:T):T{
    console.log(value,value.length);
    return value;
}
Copy the code

Practical application: Used to create reusable components, a component can support a variety of data types, components not only support current data types, but also support future data types, for large application systems to provide a very flexible function

4. Ts interface

An interface is a type of a function argument (object type interface). A function type interface defines a function, and then a type is a function type interface. The interface is used to name those types and define contracts for your code or for third-party code

  • Object type interface
interface List{ id:number; name:string; age? :number; } interface Result{ data:List[]; } function render(result:Result){ result.data.forEach((value)=>{ console.log(value.id,value.name); }) } let result = { data:[ {id:1,name:'A'}, {id:2,name:'B'}, ] } render(result)Copy the code
  • Function type interface
Type Add = (x:number,y:number) => number let Add: Add = (a,b) => a+b // version:string; doSomething():void; } function getLib(){ let lib:Lib=(()=>{}) as Lib; Lib. Version = "1.0.0"; lib.doSomething=()=>{}; return lib; } let lib1=getLib(); lib1(); lib1.doSomething(); let lib2 = getLib();Copy the code

5. Differences between ES5 inheritance and ES6 inheritance

  • 1. Create subclass ES5, instantiate the parent class and add it to subclass this
  • 2.ES6 creates the parent class first, accesses the parent by calling the super method in the instantiation subset, and implements inheritance by modifying this
  1. Es5 inheritance: create an instance of child element, and then assign attributes of parent element to an instance of chid element.
  • 1. Stereotype inheritance: Inherit the properties and methods on this using Call and apply
  • 2. Stereotype chain inheritance: Use an instance of a parent class as a stereotype of a subclass
  • 3. Composite inheritance: Use the Call Apply inheritance attribute to leverage the stereotype chain inheritance method
  1. Es6 inheritance: EXTEND inheritance is used in ES6
  • Extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends extends

Prototype and prototype chain

zhuanlan.zhihu.com/p/39549472

Each constructor has a prototype object; Every object has a constructor; Each constructor prototype is an object; Then the prototype object will also have constructors; Then the constructor of this prototype object will also have a prototype object; This creates a chain structure called a prototype chain

6. Closure

  • Js you Don’t Know describes closures that occur when a function can remember and access its lexical scope, even if the function is executed outside the current lexical scope.

  • A closure is a function that calls a variable outside its scope, or a variable in the scope chain. This reference is called a closure.

  • What closures do: Refer to the scope of a variable.

  • The purpose of closures is to read variables inside functions as mentioned earlier, and to keep the values of those variables in memory at all times.

  • Application scenario: For example, a variable changes its value when it fires an event, and another function changes its value in response.

  • Memory leaks caused by closures

  • Reason: Closures can hold local variables in a function without releasing them.

  • Solution: Define the event handler externally, unwrap the closure, or remove a reference to the DOM in the external function that defines the event handler

  • Free memory is set to null

  • Closures cause variable contamination

  • Reason: The inside function may change the value of the outside variable, causing the variable used elsewhere to be changed

() function f1 (n = 999; The function f2 () {alert (n); } return f2; } var result=f1(); result(); / / 999Copy the code

Github.com/ljianshu/Bl…

7. The arrow function this points to the question?

  • The context object this points to, and occasionally without a context object, this points to the window

  • Even call, apply, bind, etc., cannot change the direction of the arrow function this

  • The arrow function has no context, so where is the arrow function defined, so this is the parent of the arrow function defined

  • The arrow function is defined in class, so this is class

  • Ordinary functions, whoever executes it this is who, arrow functions, where do you execute them, this is where you define arrow functions, all right

M.h the TML. Cn/qa/javascri…

8.hooks

1. Definition of Hook

A Hook is a function that lets you “Hook” features like React state and lifecycle into a function component. Hooks cannot be used in Class components — this allows you to use React without using classes. React Hook is a new feature in React 16.8. It lets you use state and other React features without having to write a class.

2. UseState:

UseState returns a pair of values: the current state and a function that lets you update it, which you can call in an event handler or some other place. It is similar to the this.setState of the class component, but it does not merge the new state with the old state

3.useEffect

UseEffect is an Effect Hook that gives function components the ability to manipulate side effects. It serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount in the Class component, but has been consolidated into an API

4. Custom hook

If the function name begins with “use” and calls other hooks, we say it is a custom Hook

5.useContext

Allows you to subscribe to the React Context without using component nesting.

6.useReducer

The Reducer allows you to manage complex local states of components.

9. Performance optimization

The problem of loading too many pictures on the home page can be solved in the following ways? 1. Handle non-first-screen images by lazy loading; 2. For small ICONS with solid colors, iconfont can be adopted. For small color pictures, the Sprite diagram is used to solve the background-position attribute

10.promise

  • To solve the back-to-hell problem, the Promise object is used to represent the final completion (or failure) of an asynchronous operation and its resulting value
1. Create a Promise instance
const promise = new Promise(function(resolve, reject) { // ... Resolve (value); resolve(value); } else { reject(error); }});Copy the code
2.Promise.prototype.then()
  • The first argument to the then method is the Resolved state callback and the second argument is the Rejected state callback
getJSON("/post/1.json").then(function(post) {
  return getJSON(post.commentURL);
}).then(function (comments) {
  console.log("resolved: ", comments);
}, function (err){
  console.log("rejected: ", err);
});
Copy the code
3.Promise.prototype.catch()
// bad
promise
  .then(function(data) {
    // success
  }, function(err) {
    // error
  });

// good
promise
  .then(function(data) { //cb
    // success
  })
  .catch(function(err) {
    // error
  });
Copy the code
  • The second method is better than the first because it catches errors in the execution of the previous then method and is closer to the synchronous try/catch method. Therefore, it is recommended to always use the catch() method instead of the second argument to the then() method.
4.Promise.prototype.finally()
  • Method to specify actions that will be performed regardless of the final state of the Promise object
5.Promise.all()
const p = Promise.all([p1, p2, p3]);

Copy the code
  • Only when the states of P1, P2 and P3 become depressing, the state of P will become depressing. At this time, the return values of P1, P2 and P3 will form an array and be passed to the callback function of P.

  • If p1, P2, and P3 are rejected, P becomes rejected, and the return value of the first rejected instance is passed to p’s callback function

6.Promise.race()
const p = Promise.race([p1, p2, p3]);
Copy the code
  • In the above code, the state of P changes as long as one of the first instances of P1, P2, and P3 changes state. The return value of the first changed Promise instance is passed to p’s callback.
7.Promise.allSettled()
  • The promise.allSettled () method takes a set of Promise instances as parameters and wraps them into a new Promise instance. The wrapper instance will not complete until all of these parameter instances return the result, whether this is fulfilled or Rejected. This method was introduced by ES2020.
8.Promise.any()
  • ES2021 introduces the promise.any () method. The method takes a set of Promise instances as parameters and returns them wrapped as a new Promise instance. As long as one parameter instance becomes a depressing state, the packaging instance will become a depressing state. If all parameter instances become the Rejected state, the wrapper instance becomes the Rejected state.

  • Promise.any() is like the promise.race () method except that it does not end when a Promise changes to the Rejected state.

Wangdoc.com/es6/promise…

11. Do you know the data structure and algorithm?

There are 10 data structures: array, linked list, stack, queue, hash table, binary tree, heap, hop table, graph, Trie tree; 10 algorithms: recursion, sorting, binary search, search, hash algorithm, greedy algorithm, divide-and-conquer algorithm, backtracking algorithm, dynamic programming, string matching algorithm

Stack: A linear table that limits insert and delete operations only to the end of the table. Queue: A linear table that allows only insertion at one end and deletion at the other. String: An ordered sequence of zero or more strings. Tree: a finite set of n (n>=0) nodes. Graph: consists of a finite non-empty set of vertices and a set of edges between vertices

Bubble sort:

  • Compare adjacent elements. If the first one is larger than the second, swap them both;
  • Do the same for each pair of adjacent elements, starting with the first pair and ending with the last pair, so that the last element should be the largest;
  • Repeat for all elements except the last one;
  • Repeat steps 1 to 3 until the sorting is complete.
Function maopao(){let arr =[9,3,1,5,4,6,2,8,7]; for(let i=0; i<arr.length-1; i++){ for(let j=0; j<arr.length-1-i; j++) { if(arr[j]>arr[j+1]){ let temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; }} console.log("arr",arr)} function maopao(){let arr =[9,3,1,5,4,6,2,8,7]; for(let i=0; i<arr.length-1; i++){ let swap = false; // Set the switch state to false for(let j=0; j<arr.length-1-i; j++) { if(arr[j]>arr[j+1]){ let temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; swap = true; Log ("arr",arr)}} if (! Swap) {// If swap status is false, break loop break; }}} // If the inner loop is executed for some time without swap, it indicates that the inner loop is sorted, and the bubble ends.Copy the code

Best case: T(n) = O(n) Worst case: T(n) = O(n2) Average case: T(n) = O(n2)

Selection sort:

  • First, find the smallest (large) element in the unsorted sequence and store it at the beginning of the sorted sequence. Then, continue to find the smallest (large) element from the remaining unsorted elements and place it at the end of the sorted sequence. And so on until all the elements are sorted
Function select(){let arr =[9,3,1,5,4,6,2,8,7]; for(let i=0; i<arr.length-1; i++){ for(let j=i+1; j<arr.length-1; j++){ if(arr[j]<arr[i]) let temp = arr[i]; arr[i]= arr[j]; arr[j]=temp; }}}Copy the code

Best case: T(n) = O(n2) Worst case: T(n) = O(n2) Average case: T(n) = O(n2)

Thinkwon.blog.csdn.net/article/det… Quick sort

Blog.csdn.net/pengzonglu7…

Best case: T(n) = O(nlogn) Worst case: T(n) = O(n2) Average case: T(n) = O(nlogn)

recursive

A recursive function is a function that calls itself directly or indirectly, that is, calls itself. Two conditions to be met

  • There are repeated procedures (calling itself)
  • There are conditions to jump out of the iterative process (recursive exit)

Classic problem: factorial

Binary search

1. Data structures must be sorted first

Example: Guessing number game time complexity O(log2n)

Consistent Hash algorithm

Thinkwon.blog.csdn.net/article/det…

12. Anti-shake and throttling?

If the high-frequency event is triggered again within N seconds, the system recalculates the time.

For example: in Baidu search, there will be associative words pop up after each input, the method of control associative words is not possible to be triggered by the change of the input box content, he must be triggered when you end the input after a period of time.

Throttling: A high-frequency event fires, but only executes once in N seconds, so throttling dilutes the frequency with which the function is executed

For example: to order a function can only be executed when the execution cycle is greater than or equal to, but the call is not executed within the cycle. Just like when you buy a hot commodity on Taobao, you constantly click refresh or purchase, but there is always a period of time when the click has no effect. Here is throttling.

13. Difference between pureComponent and FunctionComponent

  • pureComponent:
  • React introduces the PureComponent concept, which makes a shallow comparison between state and props before render. If state and props are the same, render will not be called. The shallow comparison was conducted in shouldComponentUpdate, so use PureComponent when not in use shouldComponentUpdate hooks, because can override the default behavior of hooks.
  • The best case for PureComponent is to display components. If a component is updated frequently, using PureComponent simply introduces a lot of comparisons and degrades performance.

14. React to SPA and Router considerations

15. How to implement the React router? (Referring to hash)

  • In Single Page Application (SPA), routing describes the mapping between URL and UI. This mapping is one-way, that is, THE CHANGE of URL causes UI update (no Page refresh is required).
  • To implement front-end routing, two core problems need to be solved:
  1. How can I change the URL without causing a page refresh?
  2. How do I detect URL changes?

There are two implementations: hash and history

hash

Hash is the hash # and the rest of the url. Changing the hash part of the URL does not cause a page refresh.

  • Change the URL by moving the browser forward and backward
  • Change the URL by tag
  • Change the URL with window.location

Changing the URL in each of these cases triggers a Hashchange event

History provides popState listening. History provides pushState and replaceState methods, which change the path part of the URL without causing a page refresh. A POPState event is triggered when a URL is changed forward or backward by the browser. A POPState event is not triggered when a URL is changed via pushState/replaceState or a tag. Fortunately, we can intercept calls to pushState/replaceState and tag clicks to detect URL changes, so listening for URL changes is possible, but not as convenient as hashchange

16. Arrow function and general function

  • Arrow functions cannot be constructors and cannot use the new keyword

  • This has a different orientation:

    The this of the ES5 function depends on who calls it, so this refers to who; ES6 arrow functions do not have this. The inner this of the arrow function points to its outer scope. This points to whoever defines the function. That is, the arrow function does not have its own this; its this will always refer to the object that made it work, its external caller.

  • Arrow functions have no arguments

  • Arrow functions cannot use call,apply, or bind to change this

  • Yield cannot be used, and arrow functions cannot be generator functions

  • Arrow functions do not have a Prototype object.

  • Arrow functions do not have super.

  • Arrow functions do not have new.target

The original link: blog.csdn.net/leelxp/arti…

17. How is promise.all () implemented? Dictating design ideas

let p1=new Promise(resolve=>resolve('p1')); let p2=new Promise(resolve=>resolve('p2')); let p3=Promise.reject('p3 promise'); function promiseAll(promises){ return new Promise ((resolve,reject)=>{ let resultCount = 0; let results = new Array(promises.length); for(let i=0; i<promises.length; i++){ promises[i].then(item=>{ resultCount++; results[i]=item; if(resultCount==promises.length){ return resolve(results); } },error=>{ return reject(error) }) } }) } promiseAll([p1,p2,p3]).then(result=>{ console.log('111',result) }).catch(error=>{ console.log(error) })Copy the code

18. Call, apply, bind

  • Call and apply both take the first argument to this, but pass it differently
  • Call is the second and third arguments to the current function, each separated by a comma, while apply passes all arguments as an array
  • Call (window, parameter 1, parameter 1, parameter 3)
  • Call and apply are different from bind
  • Call and apply are equivalent to executing functions immediately and calling them directly when used, while bind is similar to functions that require a plus () call when used
  • Bind also passes arguments in the same way as call, passing them one by one
  1. Cookie (I interrupted you, but I forgot to answer)

20. Prevention of XSS and CSRF

1> What is an XSS attack?

  • XSS attack refers to cross-site scripting attack, which is a code injection attack. Attackers inject malicious scripts into websites to run on users’ browsers so as to steal users’ information such as cookies

2> XSS defense?

One is when malicious code is submitted (it is not recommended to translate all data due to uncertain application scenarios), and the other is when the browser executes malicious code.

  • Use pure front-end mode, do not return after server-side splicing
  • Do a good job of escaping code that needs to be inserted into HTML
  • A CSP, for example, is essentially a whitelist that tells the browser what external resources can be loaded and executed to prevent injection attacks by malicious code.
  • Cookies use HTTP-only so that scripts cannot get them
  • Captcha can also be used to prevent scripts from performing operations masquerading as users.

3> What is a CSRF attack?

A CSRF attack refers to a cross-site request forgery attack in which an attacker induces a user to a third-party website that then sends a cross-site request to the site being attacked. If a user saves the login status in the attacked website, the attacker can use this login status to bypass the background user authentication and impersonate the user to perform some operations to the server.

4> How do I prevent CSRF attacks? 1. In the method of origin detection, the server determines whether the request is an accessible site according to the origin or referer information in the HTTP request header. Use CSRF Token for authentication 3. Use double Cookie authentication 4. Use Samesite when setting the cookie property, in strict mode

21. Analyze the weights of the CSS based on specific examples

  • Priority:
  • Rules:! Important > Inline Style > ID selector > Class selector = Property selector = pseudo-class selector > tag selector = pseudo-element selector
  • The first level is inline style, which is 1000, the second level is ID selector, which is 0100, and the third level is class selector, pseudo-class selector, and property selector, which is 0010.
  • The fourth level, for element selectors and pseudoelement selectors, is 0001

22. Element of unknown width and height is in the center (ready, but not ready)

23. Box model, if width=100px, what is the width of each part of the box

24. If background-color: red is set, what is the background of each part of the box model?

25. CSS position position and difference (talking about the relationship with document flow)

  • Relative: The position of an element is moved relative to its original position, and the element still occupies the original space.
  • Absolute: The position of an element relative to the nearest positioned parent, or if the element has no positioned parent, its position relative to. Absolute positioning makes the position of an element independent of the document flow and therefore does not take up space.
  • Fixed: The position of the element is fixed relative to the browser window, even if the window is scrolling it will not move. Fixed positioning makes the position of the element independent of the document flow and therefore does not take up space
  • Static automatic positioning is the automatic positioning of elements by THE HTML in a normal document flow on a page

26. The difference between HTTP and HTTPS

  • HTTPS requires you to apply for a certificate from a CA. Generally, there are few free certificates, so a certain cost is required.
  • HTTP is a hypertext transmission protocol, and information is transmitted in plain text. HTTPS is a secure SSL encryption transmission protocol.
  • HTTP and HTTPS use completely different connections and use different ports, the former 80 and the latter 443.
  • HTTP connections are simple and stateless; HTTPS is a network protocol that uses SSL and HTTP to encrypt transmission and authenticate identity. It is more secure than HTTP

27. JS garbage collection mechanism (this point the interviewer said that JS garbage collection mechanism is actually many, I said only one algorithm)

Mark clear reference record

28. Differences between TCP and UDP

  • TCP connection-oriented (for example, dial up to establish a connection before making a phone call); UDP is connectionless, that is, no connection is required before sending data

  • TCP provides reliable services. That is to say, data transmitted through the TCP connection is error-free, not lost, not repeated, and in order to arrive; UDP does its best to deliver, i.e. reliable delivery is not guaranteed

  • TCP byte stream oriented, in fact, TCP treats data as a series of unstructured byte streams; UDP is packet oriented

  • UDP does not have congestion control, so network congestion does not slow down the sending rate of the source host (useful for real-time applications such as IP telephony and real-time video conferencing).

  • Each TCP connection can be point-to-point only. UDP supports one-to-one, one-to-many, many-to-one and many-to-many interactive communication

  • TCP header cost 20 bytes; The header of UDP has a small overhead of only 8 bytes

  • TCP logical communication channel is full-duplex reliable channel, UDP is unreliable channel

29. The difference between processes and threads

  • A process is the smallest unit of resource allocation and a thread is the smallest unit of program execution.
  • Processes have their own independent address space, and each time a process is started, the system allocates the address space to it
  • Threads, on the other hand, share data in the process, using the same address space
  • The communication between threads is more convenient. Threads under the same process share data such as global variables and static variables, and the communication between processes needs to be carried out in the way of communication (IPC)
  • But multithreaded programs are more robust. If one thread dies, the entire process dies, and the death of one process does not affect the other process, because the process has its own address space.

Blog.csdn.net/qq_40574571…

30. What is the fastest data structure if data needs to be inserted and deleted

31. If you also need to consider the indexable nature of the data, what is the best data structure

32. Enter a URL to describe the entire process

  • Perform DNS domain name resolution on www.baidu.com to obtain the corresponding IP address.

  • Based on this IP address, find the corresponding server and initiate the TCP three-way handshake.

  • TCP is a lower connection protocol than HTTP. (IP is the layer below TCP.)

  • The server responds to the HTTP request, and the browser gets the HTML code

  • The browser parses the HTML code and requests resources (such as JS, CSS, images, etc.) within the HTML code

  • (Get the HTML code before you can find the resources.)

  • The browser renders the page to the user

  • The server closes the TCP connection

  • Answer:

  • Explain the process of getting the HTML from the URL first, then focus on the HTML rendering process, and then ask the interviewer again to measure and answer (e.g. : rearrange, redraw, TCP 3 times shake hands 4 times wave hands).

33. What are the algorithms and methods to reduce repeated operations during DNS resolution

34. Var let const do not write the difference

  1. Variables declared by var are mounted on the window, while variables declared by let and const are not
  2. Var declares variables with variable promotion, let and const do not
  3. Let and const declarations form block scopes
  4. Let and const cannot declare variables of the same name in the same scope, whereas var does
  5. Const, once declared to be assigned, cannot use null placeholders; No further modification can be made after the declaration; If you are declaring compound type data, you can modify its properties

35. The principle of promise

Mp.weixin.qq.com/s/6Jsz_mskT…

36. Typeof Determines the data type

let arr=[]; let a=1; let b=""; let c=true; let d={}; let e=null; let f=undefined; console.log(arr, typeof arr); //[] "object" console.log(a, typeof a); // 1 "number" console.log(b, typeof b); // string console.log(c, typeof c); // true "boolean" console.log(d, typeof d); // {} "object" console.log(e, typeof e); // null "object" console.log(f, typeof f); // undefined "undefined"Copy the code

37. Use the instanceof

Instanceof is an instanceof B used to determine whether A is an instanceof b. the expression A instanceof B returns true if A is an instanceof B, false otherwise. It should be noted that instanceof is a prototype. Instanceof can only be used to determine whether two objects belong to an instance relationship, but not what type an object instance belongs to

console.log(true instanceof Boolean); // false console.log(1 instanceof Number); // false console.log('abc' instanceof String); // false console.log(undefined instanceof Object); // false console.log([1,2,3]] instanceof Array); // true console.log(null instanceof Object); // false console.log({name:"hao"}} instanceof Object); // true console.log(function(){} instanceof Function); // true var bool2 = new Boolean() console.log(bool2 instanceof Boolean); // true var num2 = new Number() console.log(num2 instanceof Number); // true var str2 = new String() console.log(str2 instanceof String); // true function Person(){} var per = new Person() console.log(per instanceof Person); // true function Student(){} Student.prototype = new Person() var haoxl = new Student() console.log(haoxl instanceof Student); // true console.log(haoxl instanceof Person); // trueCopy the code

Instanceof does not distinguish undefined from NULL, and does not test for primitive types that are not declared with new. It also detects multiple levels of inheritance for types that are declared with new.

Use constructor

Constructor is a property of prototype. When a function is defined, the JS engine adds the prototype to the function and the constructor property points to the function reference. Overriding prototype therefore loses the original constructor. Undefined and null have no contructor properties

console.log(true.constructor === Boolean); // true console.log(1.constructor === Number); // true console.log("abc".constructor === String); // true console.log([1,2,3]]. Constructor === Array); // true console.log({name:'hao'}.constructor === Object); // true console.log(function(){}.constructor === Function); // true console.log(haoxl.constructor === Student); // false console.log(haoxl.constructor === Person); // trueCopy the code

Constructor cannot detect undefined and null, and it is unsafe to use it because contructor’s orientation can be changed

39. ToString is perfect

ToString () is a prototype method for Object that, by default, returns the current Object’s [[Class]]. For Object objects, toString() returns [Object Object]. For other objects, you need call/apply to return the correct type information.

Object.prototype.toString.call('') ; // [object String] Object.prototype.toString.call(1) ; // [object Number] Object.prototype.toString.call(true) ; // [object Boolean] Object.prototype.toString.call(Symbol()); //[object Symbol] Object.prototype.toString.call(undefined) ; // [object Undefined] Object.prototype.toString.call(null) ; // [object Null] Object.prototype.toString.call(new Function()) ; // [object Function] Object.prototype.toString.call(new Date()) ; // [object Date] Object.prototype.toString.call([]) ; // [object Array] Object.prototype.toString.call(new RegExp()) ; // [object RegExp] Object.prototype.toString.call(new Error()) ; // [object Error] Object.prototype.toString.call(document) ; // [object HTMLDocument] Object.prototype.toString.call(window) ; //[object global] window is a reference to globalCopy the code

40.for… of

The purpose of the Iterator interface is to provide a unified access mechanism for all data structures. Of circulation