首页 > 【面经】字节前端开发工程师一面代码题面经
头像
HUST77
发布于 2022-03-02 16:29
+ 关注

【面经】字节前端开发工程师一面代码题面经

1. 作用域

let value = 1;
function foo() {
console.log(value);
}
function bar() {
let value = 2;
foo();
}
bar() //1

2.this指向

window.name = 'ByteDance';
function A () {
    this.name = 123;
}
A.prototype.getA = function () {
    return this.name + 1;
};
let a = new A();
let funcA = a.getA;
console.log(funcA());//ByteDance1
console.log(a.getA());//124


3.this指向

const obj = {
    birth: 1990,
    getAge: function (year) {
        let fn = y => y - this.birth;
        return fn.call({ birth: 2000 }, year);
    }
};
console.log(obj.getAge(2020));

***循环

async function async1() {
    console.log('async1 start'); //2
    await async2();
    console.log('async1 end'); //6
async function async2() {
    console.log('async2'); //3
    }
}

console.log('script start'); // 1

setTimeout(function () {
    console.log('setTimeout');//8
}, 0);

async1(); 

new Promise(function (resolve) {
    console.log('promise1'); //4
    resolve();
}).then(function () {
    console.log('promise2'); //7
});
console.log('script end'); //5

5.用两个栈模拟队列

6.实现一个 function sqrt(x) {} 函数。计算并返回 x 的平方根,其中 x 是非负整数。



更多模拟面试

全部评论

(4) 回帖
加载中...
话题 回帖