写在前面
互联网行业已是凛冬,希望大家抱团取暖,多多分享面试题之类的,这样既能促进相互学习,也能为自己查漏补缺。
话不多,上题:
1、原生JS操作DOM增删改查:现在大多数都使用框架,原生JS确实有所生疏
// 增
document.createElement()
// 删
let node = document.querySelector()
node.remove()
node.parentNode.removeChild()
// 改
let node = document.querySelector()
node.innerHtml = ''
node.innerText = ''
// 查
document.getElementById()
document.getElementsByTagName()
document.getElementsByClassName()
document.getElementsByName()
document.querySelector()
document.querySelectorAll()
2、查询body下所有元素的集合
let nodes = document.body.getElementsByTagName('*')
3、数组扁平化,不用循环和递归(2种以上)
// 1、ES6数组扁平化API
let arr = [[1,2,3],[4,5,6]]
arr = arr.flat()
// 2、转字符然后分割进数组
let arr = [[1,2,3],[4,5,6]];
arr = arr+'';
let res = [arr.split(',')]
4、统计数组中所有元素出现的个数
var getItemTiems = function(arr){
return arr.reduce((total,current)=>{
if(current in total){
total[current] ++;
}else{
total[current] = 1;
}
return total;
},{})
}
console.log(getItemTiems([1,1,2,1,4,3,4])) // {'1':3,'2':1,'3':1,'4':2}
5、JS封装http请求
这个后面会专门拿出来写一篇文章
6、http1和2还有https的区别?
http1和2的区别:
1、http2 采用的是二进制格式,取消了文本格式
2、http2 完全多路复用,并不是有序的,形成阻塞的
3、http2 有报头压缩,降低了开销
4、http2 让服务器可以主动推送到客户端缓存中
http和https的区别:
1、https协议需要申请证书,大多数都是付费使用的
2、http的传输是明文传输,https则是在ssl层加密传输的
3、http默认端口为80,https则是443
7、JS数据类型
boolean、string、number、null、undefined、bigInt、symbol、object、array
8、判断数组的方法有哪些?
1、Array.isArray([])
2、[] instanceof Array
3、Object.prototype.toString.call([])
4、[].constructor == Array
9、浏览器缓存
1、cookie
存储的数据始终在同源的http请求中携带
存储数据大小为4kb,只适合保存少量数据
可以设置过期时间(在过期之前,关闭浏览器再次打开依然有效)
2、sessionStorage
不会携带在http请求中,除非手动添加
存储大小可以达到5MB
没有过期时间,但是浏览器关闭后被自动清除
3、localStorage
不会携带在http请求中,除非手动添加
存储大小可以达到5MB
没有过期时间,浏览器关闭后数据依然存在,除非手动清除
结束语:本次面试的题目还没有分享完,下一篇继续