as detailed in the title: just after the interview, I came to write down such a question. has not been tested yet, and I hope you will not test it, leaving your analysis process and answers
.1. Everything is caused by a line I wrote that uses the reduce method to sum the array:
var arr = [1,2,3];
arr.reduce((sum,value) => {
return sum + value
},0)
< hr >
2, but when the interviewer added something to it, he was a little confused:
var arr = [1,2,3];
arr.reduce((sum,value) => {
setTimeout(() => console.log(1), 0)
return sum + value
},0)
I said, first output the sum result, and then output 1 (personal understanding does not know right or wrong, he did not say much. )
< hr >3. Then he revised it again and thought about it or kept my answer
.var arr = [1,2,3];
arr.reduce((sum,value) => {
setTimeout(() => console.log(1), 1000)
return sum + value
},0)
how do you analyze and understand it?