字节一面 20248.7
算法题:
1:
Q1: 输出是啥?
Q2: 如何让其符合预期, 不使用let
js
for (var i = 0; i < 5; ++i) {
setTimeout(function (){
console.log(i + ' ');
}, 100);
}解:
js
for (let i = 0; i < 5; ++i) {
setTimeout(function (){
console.log(i + ' ');
}, 100);
}js
for (var i = 0; i < 5; ++i) {
(function(i){
setTimeout(function (){
console.log(i + ' ');
}, 100);
})(i)
}2:
js
setTimeout(function() {
console.log(1)
}, 0);
Promise.resolve().then(function () {
console.log(2);
}).then(function () {
console.log(3);
});
new Promise(function(resolve) {
console.log(4);
for(var i=0 ; i < 10000 ; i++) {
if (i == 9999) {
resolve();
}
}
console.log(5);
}).then(function() {
console.log(6);
});
console.log(7);4 5 7 2 6 3 1
3:
md
- 给定一个字符串,请你找出其中不含有重复字符的 最长子串。 aadbsssdsessswesss
var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
console.log(a);