快手前端面试都问什么?

1.以下css最后是什么颜色

<style>
    .classA{
           color:blue;
    }
    .classB{
           color:red;
    }
</style>

   <p class="classB classA">123</p>

与样式定义在文件中的先后顺序有关,即是后面的覆盖前面的,与在<p class=’classB classA’>中的先后关系无关。 

2.以下代码运行结果

   Function.prototype.a = () => alert(1);
   Object.prototype.b = () => alert(2);
   function A() {}
   const a = new A();
   a.a(); // 报错
   a.b(); // 2

3.以下代码运行结果

console.log(typeof typeof typeof null);  // string

4.如下代码展示的时候在加上position属性和未加入position属性的时候,分别会怎么显示

 

<style>
p {
 background: red;
 color: #000;
 /*
 position: absolute;
 */
}
</style>

<div>
 <span>11111</span>
 <p>2222<p>
 <span>3333</span>
</div>

不加absolute

加上

5.以下代码运行结果

var a = [1, 2, 3, 4];
function set(a) {
 a = [5, 6, 7, 8];
}
set(a);

console.log(a);  // [1,2,3,4] 函数传参按值传递

6.

var name = '123';
var obj = {
   name: '456',
   getName: function () {
       function printName () {
           console.log(this.name);
       }
       printName();
   }
}

obj.getName(); // 123

7.

var a = { x: 1 };
var b = a;
a = { n: 1 };
console.log(a); // {n: 1}
console.log(b); // {x: 1}

8.

var count = 10;
function a() {
    return count + 10;
}

function b() {
    var count = 20;
    return a();
}


console.log(b()); // 20

9.

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

setTimeout(() => {
  console.log(2);
}, 100);

// 1,2

10.

var a = 1;
function fn() { 
 console.log(a);
 var a = 2;
}
fn();  // undefined  因为已经被fn中变量提升的var覆盖了,只是没有赋值

11. 实现 bind

参考:手写bind、apply、call

12. 数组扁平化

// 1. 数组自带 flat(层数)
arr.flat(Infinity);

// 2. 先通过toString转成字符串,再塞到数组里,使用map遍历将字符串转成数字
arr.toString().split(',').map(item => +item);

// 3. reduce
const flatten = arr => arr.reduce((prev,next) => {
    return Object.prototype.toString.call(next) === '[object Array]' ? prev.concat(flatten(next)) : prev.concat(next);
},[])

// 4. 使用apply
function flat(arr) {
    let isDeep = arr.some(item => item instanceof Array)
    
    if (!isDeep) return arr;

    const res = Array.prototype.concat.apply([], arr) 
    return flat(res)

}

 

 

  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端卡卡西呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值