22/04/19
1.引用
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"
解析:
- 根据优先级判断,先执行typeof 1, 返回
number,然后执行'number' / 0的操作,此时会隐式调用Number转型函数将'number'转换成NaN。最后执行NaN / 0的操作,返回NaN - 有两个
typeof运算符,会从右往左执行。由题1可知typeof 1会返回'number',此时typeof 'number'会返回'string'。然后隐式调用Number转型函数,同题1 - 首先,
1/0 = Infinity。然后typeof Infinity = 'number' - 首先,
1/0 = Infinity,接着typeof Infinity = 'number',最后typeof 'number' = 'string' - 首先,
typeof 1 = 'number',接着'number' / 0 = NaN,最后typeof NaN = 'number'
3.Set和Map的区别;Map和Object 的区别
4.堆和栈的区别
-
空间分配不同
栈由系统自动分配释放
堆由程序员分配释放 -
缓存方式不同
栈是一级缓存,存取速度快,不灵活
堆是二级缓存,存取速度慢,较灵活
5.判断是否为数组
- 用
instanceof - 用
Array.isArray([]) - 用
Object.prototype.toString.call()
6. css面试题
7. 基于已有类型生成新类型:剔除类型中的width属性
使用泛型工具Pick
interface A {
content: string;
width: number;
height: number;
}
type B = Pick<A, 'content' | 'height'>;