判断
Date.parse(new Date())的时间戳是s吗?
是,Date.parse()函数用于分析一个包含日期的字符串,并返回该日期与 1970 年 1 月 1 日午夜之间相差的毫秒数。其最后三位永远都是0,所以只能精确到秒。
204是成功请求吗?
HTTP204状态码代表的意思是 请求已成功处理,但无返回内容,即 HTTP 204 No Content 响应状态。
<img style="display:none" src="xxx"/>
会发起请求吗?
会,图片不会渲染,但会发起http请求。
简答
es6新特性(5个以上)
- 块级作用域、块级变量let、块级常量const
- 箭头函数
- 参数处理(默认参数/...)
- 模板字面量(模板字符串)
- 对象的扩展
- 解构赋值
- 模块(import/export)
- 类(class/extends)
- Promise
数据类型有哪些
基本类型:Number、Boolean、String、null、undefined、symbol(ES6 新增的),BigInt(ES2020)
引用类型:Object,对象子类型(Array,Function)
flex-flow是哪两个的组合
flex-direction 和 flex-wrap
隐藏元素的方法
- display:none
- visibility:hidden
- opacity:0
- 绝对定位移出可视区域
- z-index负值用其他元素盖住
- clip/clip-path裁剪
- transform:scale(0,0)
css3中transform的作用
Transform属性应用于元素的2D或3D转换。这个属性允许你将元素旋转,缩放,移动,倾斜等。
代码
水平垂直居中
<div class='container'>
<div class='content'></div>
</div>
- margin: auto
- position:absolute
- flex
- text-align 和 line-height
- grid
深拷贝函数
完整版
export function deepClone(obj, hash = new WeakMap()) {
if (obj === null) return obj;
if (obj instanceof Date) return new Date(obj);
if (obj instanceof RegExp) return new RegExp(obj);
if (typeof obj !== "object") return obj;
if (hash.get(obj)) return hash.get(obj);
let cloneObj = new obj.constructor();
hash.set(obj, cloneObj);
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
cloneObj[key] = deepClone(obj[key], hash);
}
}
return cloneObj;
}
摘抄于genrate-form
export function deepClone(obj) {
const _toString = Object.prototype.toString;
if (!obj || typeof obj !== "object") {
return obj;
}
if (obj.nodeType && "cloneNode" in obj) {
return obj.cloneNode(true);
}
if (_toString.call(obj) === "[object Date]") {
return new Date(obj.getTime());
}
if (_toString.call(obj) === "[object RegExp]") {
const flags = [];
if (obj.global) {
flags.push("g");
}
if (obj.multiline) {
flags.push("m");
}
if (obj.ignoreCase) {
flags.push("i");
}
return new RegExp(obj.source, flags.join(""));
}
const result = Array.isArray(obj)
? []
: obj.constructor
? new obj.constructor()
: {};
for (const key in obj) {
result[key] = deepClone(obj[key]);
}
return result;
}
斐波那契数列算法(递归)
这么简单醉了
int fibonacci0(int n){
return (n < 2) ? n : fibonacci0(n - 1) + fibonacci0(n -2);
}
提取url参数
split分割
function getParam(url) {
const urlArr = url.split('&')
const params = {}
for(let i = 0; i < urlArr.length; i++) {
const arg = urlArr[i].split('=')
params [arg[0]] = arg[1]
}
return params ;
}
正则
function getParam(url) {
const pattern = /(\w+)=(\w+)/ig;
const params = {};
url.replace(pattern, function(a, b, c){
params [b] = c;
});
return params ;
}
Event Loop 、变量提升
下面代码输出啥
使用let
for (let index = 0; index < 3; index++) {
setTimeout(function(){
console.log('a:'+index)
}, 0);
console.log('b:'+index)
}
结果:
b:0
b:1
b:2
a:0
a:1
a:2
使用var
for (var index = 0; index < 3; index++) {
setTimeout(function(){
console.log('a:'+index)
}, 0);
console.log('b:'+index)
}
结果:
b:0
b:1
b:2
a:3
a:3
a:3
解析:var的变量提升机制,var命令实际只会执行一次,所以每次获取的都是同一个index;而let命令不存在变量提升,所以每次循环都会执行一次,声明一个新变量,但是值不同。