字节前端一面

JS数据类型有哪些?

引用数据类型和基本数据类型的区别是什么?

如何判断一个对象是不是空对象?

代码输出:

const obj1 = {
    key: 'value1',
};

const obj2 = {
    key: 'value2',
};

function func1(obj1) {
    obj1.key = 'value11';
    return obj1;
}

function func2(obj2) {
    obj2 = {
        key: 'value22',
    };
    return obj2;
}

func1(obj1);
func2(obj2);

console.log(obj1, obj2);
console.log(obj2 === func2(obj2));

对闭包的理解?什么情况下会产生闭包?

代码输出:

function func() {
    let num = 0;
    return () => {
        num++;
        return num;
    }
}

const func1 = func();
const func2 = func();

console.log(func1());
console.log(func2());
console.log(func1());
console.log(func2());

对JS单线程的理解?缺点是什么?设计初衷是什么?

浏览器从输入url到页面渲染出来的过程?

DOM树的构建和JS代码的执行的先后顺序?

对webWorker的理解?使用限制有哪些?

对JS的事件循环的理解?

代码输出

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

async function async2() {
    console.log('async2');
}

console.log('script start');

setTimeout(() => {
    console.log('setTimeout');
}, 0)

async1();

new Promise((resolve) => {
    console.log('promise1');
    resolve();
}).then(() => {
    console.log('promise2');
})

console.log('script end');

如果在async1()前面加上await会不会影响输出结果?

Promise和async/await有哪些相似性?

有了解过React框架的哪些原理吗?

React Fiber在哪个过程是可以中断的?

代码题:实现一个convert函数,将扁平化的结构转换成树状结构。

const list = [
    { key: 1, value: 'A', parentKey: 0 },
    { key: 2, value: 'B', parentKey: 0 },
    { key: 3, value: 'C', parentKey: 1 },
    { key: 4, value: 'D', parentKey: 1 },
    { key: 5, value: 'E', parentKey: 2 },
    { key: 6, value: 'F', parentKey: 3 },
    { key: 7, value: 'G', parentKey: 4 },
];

===>
    
const tree = [
    {
        key: 1,
        value: 'A',
        parentKey: 0,
        children: [
            {
                key: 3,
                value: 'C',
                parentKey: 1,
                children: [
                    { key: 6, value: 'F', parentKey: 3 }
                ]
            },
            {
                key: 4,
                value: 'D',
                parentKey: 1,
                children: [
                    { key: 7, value: 'G', parentKey: 4 }
                ]
            }
        ]
    },
    {
        key: 2,
        value: 'B',
        parentKey: 0,
        children: [
            {
                key: 5,
                value: 'E',
                parentKey: 2
            }
        ]
    }
];

代码题:实现输出下一个质数

getPrime(); // 2
getPrime(); // 3
getPrime(); // 5
// ...

代码题:给一个有序数组和一个数字,要求返回该数字在有序数组中出现的起始位置和结束位置。

const arr = [1, 1, 2, 2, 2, 3, 4];
const n = 2;
getPosition(arr, n); // 输出: [2, 4]
全部评论
什么部门兄弟
1
送花
回复
分享
发布于 2023-08-30 13:03 河北
是实习嘛,为啥这么简单
点赞
送花
回复
分享
发布于 2023-08-31 20:05 甘肃
秋招专场
校招火热招聘中
官网直投

相关推荐

投递美团等公司10个岗位
点赞 评论 收藏
转发
6 28 评论
分享
牛客网
牛客企业服务