The introduction

Update: wechat search “advanced front interview” small program, brush on the way to work, half a year assault into dafang!

Update: the current has reached “23K” Star, thank you for your support, recently a blog site out, convenient for everyone to read, the follow-up will have more content and more optimization, fierce poke here to view

—— The following is the text ——

In half a year, thousands of people participated in the interview and selected 100 high frequency questions, which is “one question”.

On January 21, 2019, the “One Question” project officially started. After that, a high-frequency interview question will be set every working day, mainly covering large companies such as Ali, Tencent, Tiaotiao, Baidu, netease and common questions. Thanks to your enthusiastic participation, there are many answers to each question, and the ideas and answers provided have greatly increased my knowledge. Up to now, I have accumulated 100 questions, “8000+” Star. It can be said that you have met the questions in the interview, and I am sure that you can find familiar figures here.

In the later stage, in addition to continuously updating “one question”, we will also sort out very detailed answer analysis, provide a complete thinking link, and help you better understand the topic, as well as the knowledge behind the topic. “Our goal is not to memorize the topic, but to make up for the gaps through the topic, and to review the old and new”.

For more details and answers, check out here

Questions 1 to 10

When writing React/Vue projects, why do we write key in the list component and what is its function?

1


Question 2:['1', '2', '3'].map(parseInt) what & why ?

2


Question 3 :(dig money) what is shockproof and throttling? What’s the difference? How?

3


Topic 4: Introduce the difference between Set, Map, WeakSet and WeakMap?

4


Question 5: how to implement depth-first traversal and breadth-first traversal?

5


Question 6: Can you implement a copy function using depth-first and breadth-first ideas, respectively?

6


Question 7: What is the difference in ES5/ES6 inheritance other than the way it is written?

7


8. What is the difference between setTimeout, Promise and Async/Await

8


9. How can Async/Await be implemented in a synchronous way

9


Question 10 :(headline) asynchronous pen test questions

Write the result of the following code

async function async1() {
    console.log('async1 start');
    await async2();
    console.log('async1 end');
}
async function async2() {
    console.log('async2');
}
console.log('script start');
setTimeout(function() {
    console.log('setTimeout');
}, 0)
async1();
new Promise(function(resolve) {
    console.log('promise1');
    resolve();
}).then(function() {
    console.log('promise2');
});
console.log('script end');
Copy the code

10


Problem 11 to 20

11 :(ctrip) algorithm handwriting problem

The following array is known:

var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];

Write a program that flattens and divides the duplicate parts of the array, resulting in an ascending and non-duplicate array

11


Question 12 :(didi, wacai, weidoctor, haikang) JS asynchronous solution development process and advantages and disadvantages.

12


Question 13: Is the Promise constructor executed synchronously or asynchronously? What about the THEN method?

13


14. How to implement a new on Valentine’s Day

14


Question 15 :(netease) briefly explain http2 multiplexing

15


Question 16: Tell me about your understanding of the TCP three handshake and four wave

16


Question 17: After the normal connection of machine A and B, machine B suddenly restarts. What is the TCP state of MACHINE A at this time

If A and B have established A normal connection but have never sent data to each other, then B suddenly restarts. What is the TCP status of A at this time? How do I eliminate this state in my server program? (Super outline question, understand can)

17


Q: When is setState synchronized in React? When is setState asynchronous?

18


19. React setState: What does the following code output?

class Example extends React.Component {
  constructor() {
    super(a);this.state = {
      val: 0
    };
  }
  
  componentDidMount() {
    this.setState({val: this.state.val + 1});
    console.log(this.state.val);    // The first log

    this.setState({val: this.state.val + 1});
    console.log(this.state.val);    // The second log

    setTimeout(() = > {
      this.setState({val: this.state.val + 1});
      console.log(this.state.val);  // The third log

      this.setState({val: this.state.val + 1});
      console.log(this.state.val);  // Fourth log
    }, 0);
  }

  render() {
    return null; }};Copy the code

19


Question 20: Introduce the installation mechanism of NPM module. Why can you automatically install the corresponding module by typing NPM install?

20


Problem 21-30

Question 21: There are three ways to judge an array. Please describe the differences between them

Object. The prototype. ToString. Call (), instanceof and Array. The isArray ()

21


Question 22: What about Repaint & Reflow and how to optimize it

22


Question 23: Describe the difference between the observer pattern and the subscription-publish pattern. What scenarios does each apply

23


Question 24: Talk about the design ideas of Redux and Vuex

24


Question 25: Describe the difference between browser and Node event loops

25


Question 26: Introduce the development of modularity

This can be considered from IIFE, AMD, CMD, CommonJS, UMD, Webpack (require.ensure), ES Module,

26


In global scope, variables declared as const and let are not in Windows. Where are they? How to get it? .

27


Question 28: Both cookies and tokens are stored in the header. Why not jack the token?

28


Question 29: How does the Model change the View and how does the View change the Model

29


Problems 31-40

Problem 30: Merge two arrays into one array

Please put the two arrays [‘ A1 ‘, A2, B1, B2, C1, C2, D1, ‘D2] and [‘ A’, ‘B’, ‘C’, ‘D’]. Combined into [‘ A1 ‘, ‘A2’, ‘A’, ‘B1, B2,’ B ‘, ‘C1, C2,’ C ‘, ‘D1, D2,’ D ‘].

30


Problem 31: Modify the following code to output 0-9, and write all the solutions you can think of.

for (var i = 0; i< 10; i++){
	setTimeout(() = > {
		console.log(i);
    }, 1000)}Copy the code

31


Question 32: Is the Virtual DOM really faster than the native DOM? Tell me what you think.

32


Question 33: What does the following code print and why?

var b = 10;
(function b(){
    b = 20;
    console.log(b); }) ();Copy the code

33


Question 34: Simply modify the following code to print 10 and 20, respectively.

var b = 10;
(function b(){
    b = 20;
    console.log(b); }) ();Copy the code

34


Question 35: Browser cache reading rules

Can be divided into Service Worker, Memory Cache, Disk Cache and Push Cache. What is the basis for the request from Memory Cache and from Disk Cache? What data is stored in Memory Cache and Disk Cache and when?

35


Problem 36: Implement the flatten function iteratively.

36


Question 37: Why can’t asynchronous operation be performed in the reducer of Vuex mutation and Redux?

37


Question 38 :(jd) under what circumstances does a in the following code print 1?

vara = ? ;if(a == 1 && a == 2 && a == 3) {console.log(1);
}
Copy the code

38


Question 39: Introduce BFC and its applications.

39


Question 40: In Vue, why can’t child components modify Prop passed by parent components

If so, how does Vue monitor the property changes and give warnings?

40


Problem 41 to 50

Question 41: What does the following code output

var a = 10;
(function () {
    console.log(a)
    a = 5
    console.log(window.a)
    var a = 20;
    console.log(a)
})()
Copy the code

41


Problem 42: Implement a sleep function

For example, sleep(1000) means waiting for 1000 milliseconds and can be implemented from the perspective of Promise, Generator, Async/Await, etc

42


Problem 43: Use sort() to sort the arrays [3, 15, 8, 29, 102, 22] and output the result

43


Question 44: Introduce the HTTPS handshake process

44


Question 45: How does the client verify the validity of the certificate during the HTTPS handshake

45


Question 46: Output the result of the following code execution and explain why

var obj = {
    '2': 3.'3': 4.'length': 2.'splice': Array.prototype.splice,
    'push': Array.prototype.push
}
obj.push(1)
obj.push(2)
console.log(obj)
Copy the code

46


Question 47: does the bidirectional binding and vuEX conflict

47


48. What is the difference between call and apply

48


Question 49: Why are transparent 1×1 GIF images usually used when sending data burial requests?

49


第 50 题 :(baidu) implement (5).add(3).minus(2).

Example: 5 + 3-2, the result is 6

50


Problems 51 to 60

Question 51: What are the defects in the response principle of Vue’s Object. DefineProperty?

Why does Vue3.0 use Proxy instead of Object.defineProperty?

51


Question 52: How do I center a div horizontally or vertically

52


Question 53: Output the execution result of the following code and explain why

var a = {n: 1};
var b = a;
a.x = a = {n: 2};

console.log(a.x) 	
console.log(b.x)
Copy the code

53


Question 54: How is bubble sort implemented, what is the time complexity, and how can it be improved?

54


Question 55: A company’s sales from January to December are stored in an object

As follows: {1:222, 2:123, null, null, 888, NULL, null, null, null, null, null, null, null, null, null, null, null.

55


Question 56: The LazyMan class is required to implement the following functions.

LazyMan('Tony');
// Hi I am Tony

LazyMan('Tony').sleep(10).eat('lunch');
// Hi I am Tony
// Wait 10 seconds...
// I am eating lunch

LazyMan('Tony').eat('lunch').sleep(10).eat('dinner');
// Hi I am Tony
// I am eating lunch
// Wait 10 seconds...
// I am eating diner

LazyMan('Tony').eat('lunch').eat('dinner').sleepFirst(5).sleep(10).eat('junk food');
// Hi I am Tony
// Wait 5 seconds...
// I am eating lunch
// I am eating dinner
// Wait 10 seconds...
// I am eating junk food
Copy the code

56


第 57 题 : Analyze the advantages and disadvantages of opacity: 0, visibility: hidden, and display: None and their applicable scenarios.

57


Question 58: What is the difference between an arrow function and an ordinary function? Constructors (functions) can use new to generate instances, but can arrow functions? Why is that?

58


Problem 59: Given two arrays, write a method to calculate their intersection.

For example, given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].

59


Question 60: Given the following code, how can I change the image width to 300px? Note that the following code cannot be modified.

<img src="1.jpg" style="width:480px! Important." >

60


Problems 61 to 70

Question 61: How to implement token encryption

61


Why should Redux design Reducer as a pure function

62


Question 63: How to design for seamless rotation

63


Question 64: Simulate the implementation of a promise.finally

64


65:a.b.c.da['b']['c']['d'], which has higher performance?

65


Question 66: What is the idea of translating ES6 code into ES5 code

66


Question 67: Array programming

Randomly generate an array of integer types of length 10, such as [2, 10, 3, 4, 5, 11, 10, 11, 20], and arrange it into a new array of the following form, such as [[2, 3, 4, 5], [10, 11], [20]].

67


Question 68: How to solve the problem of 1px pixels of mobile Retina screen

68


Question 69: How to invert the case of a string, such as’ AbC’ to ‘AbC’.

69


Question 70: Describe the principle of webpack hot update. How do you update a page without refreshing the browser

70


Problem 71 to 80

Question 71: Implement a string matching algorithm. From a string S of length n, it looks for a string T, whose length is m, and returns the position if it exists.

71


Question 72: Why ordinaryforThe performance of loops is much higher thanforEachPlease explain why.

72


Question 73: Introduce BFC, IFC, GFC and FFC

73


74. Simple data binding using JavaScript Proxy

74


Question 75: There are 100,000 pieces of data in the array. What is the time difference between the first element and the 100,000th element

75


Question 76: Output the following code run result

// example 1
var a={}, b='123', c=123;  
a[b]='b';
a[c]='c';  
console.log(a[b]);

---------------------
// example 2
var a={}, b=Symbol('123'), c=Symbol('123');  
a[b]='b';
a[c]='c';  
console.log(a[b]);

---------------------
// example 3
var a={}, b={key:'123'}, c={key:'456'};  
a[b]='b';
a[c]='c';  
console.log(a[b]);
Copy the code

76


Question 77: Algorithm “Rotate arrays”

Given an array, move the elements of the array k positions to the right, where k is non-negative.

Example 1:

Input:1.2.3.4.5.6.7] and k =3Output:5.6.7.1.2.3.4[Explanation: Rotate to the right1Step:7.1.2.3.4.5.6[Turn to the right2Step:6.7.1.2.3.4.5[Turn to the right3Step:5.6.7.1.2.3.4]
Copy the code

Example 2:

Input: [...1, -100.3.99] and k =2Output:3.99, -1, -100[Explanation: Rotate to the right1Step:99, -1, -100.3[Turn to the right2Step:3.99, -1, -100]
Copy the code

77


Question 78: What is the order in which Vue’s parent and child lifecycle hooks are executed

78


Question 79: How is the input search stabilized and how is the Chinese input handled

79


Question 80: Introduce the use, principle implementation and error handling of Promise.all

80


Problem 81-90

Problem 81: Print out all symmetric numbers between 1 and 10000

For example, 121, 1331, etc

81


Problem 82: Monday algorithm problem “Move zero”

Given an array nums, write a function to move all zeros to the end of the array while preserving the relative order of the non-zero elements.

Example:

Input: [0,1,0,3,12] output: [1,3,12,0,0]Copy the code

Description:

  1. You must operate on the original array; you cannot copy additional arrays.

  2. Minimize the number of operations.

82


Question 83: How is the distinction between var, let, and const implemented

83


Question 84: Please implement an ADD function that fulfils the following functions.

add(1); 			/ / 1
add(1) (2);  	/ / 3
add(1) (2) (3);/ / 6
add(1) (2.3); / / 6
add(1.2) (3); / / 6
add(1.2.3); / / 6
Copy the code

84


Question 85: From the React-Router<Link>The labels and<a>What’s the difference between labels

How to disable the TAB default event, and how to implement jump after disabling.

85


Question 86 :(jingdong, kuaishou)

Given an array of integers and a target value, find the two numbers in the array and the target value.

You can assume that each input corresponds to only one answer, and that the same elements cannot be reused.

Example:

Given nums = [2.7.11.15], target = 9Because the nums [0] + nums[1] = 2 + 7 = 9So return [0.1]
Copy the code

86


Question 87: How to determine if you have entered a correct url in the input box.

87


Problem 88: Implementing the convert method to convert the original list into a tree structure requires as little time complexity as possible

In the following data structure, id represents the department number, name is the department name, parentId is the parent department number, and 0 represents the primary department, we need to implement a convert method to convert the original list into a tree structure. The value of parentId is mounted in the children array of the id attribute. The structure is as follows:

// The original list is as follows
let list =[
    {id:1.name:'A'.parentId:0},
    {id:2.name:'B'.parentId:0},
    {id:3.name:'C'.parentId:1},
    {id:4.name:'D'.parentId:1},
    {id:5.name:'E'.parentId:2},
    {id:6.name:'department F'.parentId:3},
    {id:7.name:'department G'.parentId:2},
    {id:8.name:'H'.parentId:4}];constresult = convert(list, ...) ;// The result is as follows
let result = [
    {
      id: 1.name: 'A'.parentId: 0.children: [{id: 3.name: 'C'.parentId: 1.children: [{id: 6.name: 'department F'.parentId: 3
            }, {
              id: 16.name: 'department L'.parentId: 3}]}, {id: 4.name: 'D'.parentId: 1.children: [{id: 8.name: 'H'.parentId: 4}]}]}, ···];Copy the code

88


Question 89: Design and implement promise.race ()

89


Problem 90: Keyword highlighting for fuzzy search results

90


Problem 91-100

Question 91: Introduce HTTPS man-in-the-middle attack

91


Problem 92: Given the data format, implement a function fn to find all parent ids in the chain

const value = '112'
const fn = (value) = >{... } fn(value)// Output [1, 11, 112]
Copy the code

92


Problem 93: Given two ordered arrays of size m and n, nums1 and nums2. Find the median of the two ordered arrays. The time complexity of the algorithm is order log(m+n)).

Example 1:

nums1 = [1.3]
nums2 = [2]
Copy the code

The median is 2.0

Example 2:

nums1 = [1.2]
nums2 = [3.4]
Copy the code

The median is (2 + 3) / 2 = 2.5

93


Question 94: Does vue need an event proxy to bind events to each element in v-for? Why is that?

94


Problem 95: Simulate a deep copy and consider the case where objects reference each other and Symbol copies are made

95


Question 96: Introduce the common scenarios and methods of front-end encryption

96


Question 97: React and Vue diff time complexity is optimized from O(n^3) to O(n), so how are O(n^3) and O(n) calculated?

97


Question 98 :(jd.com) write a printout of the following code

function changeObjProperty(o) {
  o.siteUrl = "http://www.baidu.com"
  o = new Object()
  o.siteUrl = "http://www.google.com"
} 
let webSite = new Object(a); changeObjProperty(webSite);console.log(webSite.siteUrl);
Copy the code

98


Question 99 :(bilibili) programming algorithm

Write a function in JavaScript that enters an int and returns a string of integers in reverse order. For example, if you enter the integer 1234, the value 4321 is returned. Requires that recursive function calls must be used, that global variables cannot be used, that input functions must be passed with only one argument, and that they must return a string.

99


Question 100 :(jd.com) please write a printout of the following code

function Foo() {
    Foo.a = function() {
        console.log(1)}this.a = function() {
        console.log(2)
    }
}
Foo.prototype.a = function() {
    console.log(3)
}
Foo.a = function() {
    console.log(4)
}
Foo.a();
let obj = new Foo();
obj.a();
Foo.a();
Copy the code

100


❤️ see three things

If you found this post inspiring, I’d like to invite you to do three small favors for me:

  1. Like, let more people can also see this content (collection does not like, is playing rogue – -)
  2. Follow me on GitHub and make it a long-term relationship
  3. Pay attention to the public number “advanced front-end advanced”, focus on solving a front-end interview difficult points every week, the public number background reply “data” to send you selected front-end quality data.