前端日常面经收集

191 阅读1分钟

22/04/19

1.引用

截图222.png

截图333.png

2.typeof运算符

优先级从高到低排
圆括号() > typeof运算符> 除法

typeof 1/0 => (typeof 1)/0 => 'number'/0 => NaN   // NaN 
typeof typeof 1/0 => (typeof(typeof 1))/0 =>(typeof 'number')/0 =>NaN // NaN 
typeof(1/0) => typeof(infinity)  // "number"  
typeof typeof(1/0) => typeof 'number' => // "string" 
typeof(typeof 1/0) => typeof NaN =>  // "number"

解析:

  1. 根据优先级判断,先执行typeof 1, 返回number,然后执行'number' / 0的操作,此时会隐式调用Number转型函数将'number'转换成NaN。最后执行NaN / 0的操作,返回NaN
  2. 有两个typeof运算符,会从右往左执行。由题1可知typeof 1会返回'number',此时typeof 'number'会返回'string'。然后隐式调用Number转型函数,同题1
  3. 首先, 1/0 = Infinity。然后typeof Infinity = 'number'
  4. 首先,1/0 = Infinity,接着typeof Infinity = 'number',最后typeof 'number' = 'string'
  5. 首先,typeof 1 = 'number',接着'number' / 0 = NaN,最后typeof NaN = 'number'

3.Set和Map的区别;Map和Object 的区别

juejin.cn/post/707743…

4.堆和栈的区别

  1. 空间分配不同
    栈由系统自动分配释放
    堆由程序员分配释放

  2. 缓存方式不同
    栈是一级缓存,存取速度快,不灵活
    堆是二级缓存,存取速度慢,较灵活

5.判断是否为数组

  1. instanceof
  2. Array.isArray([])
  3. Object.prototype.toString.call()

6. css面试题

blog.csdn.net/weixin_3916…

7. 基于已有类型生成新类型:剔除类型中的width属性

使用泛型工具Pick

interface A {
  content: string;
  width: number;
  height: number;
}

type B = Pick<A, 'content' | 'height'>;