One side of Didi|Front-end Development Engineer|Didi Shunfeng Department

First, I introduced myself, and then asked me js, css, which algorithm is better, I said js. Then asked me how the algorithm was, and I said so.
Then began to interview me my js foundation

js

This interview is all code questions, so post the code directly

first question

	Object.prototype.a='a';
		Function.prototype.a='a1';
		function Person(){
    
    };
		var didi = new Person();
		
		 console.log(didi.a); 
		 console.log(Person.a);
		 console.log(didi.__proto__.__proto__.constructor.constructor);

Insert picture description here
I didn’t answer the third one. The prototype chain needs to be studied hard; explain what a prototype chain is;

Second question

 function bar(){
    
    
			 console.log(myName);
			 
		 }
		 function foo(){
    
    
			 var myName = 'xiaojv';
			 bar()
		 }
		 foo()
		 var myName='didi';

Insert picture description here
The knowledge of this design variable promotion has not been studied well;

Third question

<body>
		<button id="test">test第三题</button>
	</body>
<script>
//点击按钮有反应吗,为什么,怎么解决
		 $('#test').click(function(argument){
    
    
			 console.log(1)
		 });
		 while(true){
    
    
			 console.log(Math.random());
		 }
		 setTimeout(()=>{
    
    
			 console.log(1);
		 })
</script>

This is mainly the knowledge of eventloop, the execution order of macro tasks and micro tasks;

Fourth question

 var Object={
    
    
			 a:5,
			 method:function(){
    
    
				 console.log(this.a);
			 // }
		 }
		 var b = Object.method;
		  // var b = Object.method.bind(null);
		  // Object.method.call(null);
		 b();

After this, I asked about the difference between bind, call, and apply;
let me also talk about the difference between foreach, for...in... for... of;

Algorithm question

1. Calculate the student grades of students between 0-100. For example, 90-100 is grade 1, 0,890 is grade 2, and so on. If switch, etc. are not allowed;

答案:例如这个数为82,需要算出282/100=0.821-0.82=0.180.18*10=1.8
1.8=2

2. String calculation

题目:一个字符串‘2*7-1/3+3*3’,求计算值

This lets hand-written code. Written but did not consider the probability of multiple situations;

Rhetorical question

Let the interviewer mention his shortcomings.
The interviewer said that my js foundation is not very good and the algorithm needs to be practiced.

Generally speaking, this interviewer pays more attention to the basic knowledge of js. Very good, every time I encounter a question that I didn't reply to, I will help me reason and answer it. Keep learning~

Guess you like

Origin blog.csdn.net/weixin_43902063/article/details/115276141