应聘前端开发的一次笔试题目(某电信子公司)

js部分

1. localStorage, sessionStorage和cookie的区别

  localStorage: 本地存储, 除非特意清除数据, 否则一直保存.

  session: 会话, 保存一部分数据在当前会话, 刷新页面依然存在, 关闭页面或浏览器后清空.

  cookie: 一般由服务器设置有效时间, 大小限制4kb, 主要用途保存登录信息, 如记住密码, 通过在cookie存入一段辨别用户身份的数据来实现.

  详见【Reference 1】

2. 下面代码运行后输出结果(javascript事件循环机制)

 1 //请写出输出内容
 2 async function async1() {
 3     console.log('async1 start');
 4     await async2();
 5     console.log('async1 end');
 6 }
 7 async function async2() {
 8     console.log('async2');
 9 }
10 
11 console.log('script start');
12 
13 setTimeout(function() {
14     console.log('setTimeout');
15 }, 0)
16 
17 async1();
18 
19 new Promise(function(resolve) {
20     console.log('promise1');
21     resolve();
22 }).then(function() {
23     console.log('promise2');
24 });
25 console.log('script end');

  参考:

script start
async1 start
async2
promise1
script end
async1 end
promise2
setTimeout

  详见【Reference 2】

3. ES6作用域及let和var的区别

  参考: let声明的变量相对于var, 区别在于: 

  (1) 只在其所在的块级作用域有效.

  (2) 不存在变量提升过程.

  (3) 存在“暂时性死区”.

  (4) 不允许重复声明.

  (5) let声明的全局变量不会作为window对象的一个属性.

  详见【Reference 3】

4. 下面代码输出结果(闭包)

 1 function fun(n,o) {
 2   console.log(o)
 3   return {
 4     fun:function(m){
 5       return fun(m,n);
 6     }
 7   };
 8 }
 9 var a = fun(0);  
10 a.fun(1);  a.fun(2);
11 a.fun(3);
12 var b = fun(0).fun(1).fun(2).fun(3);
13 var c = fun(0).fun(1);
14 c.fun(2);  c.fun(3);
15 //问:三行a,b,c的输出分别是什么?

  参考:

var a = fun(0); a.fun(1); a.fun(2); a.fun(3);
//undefined 0 0 0 

var b = fun(0).fun(1).fun(2).fun(3);
//undefined 0 1 2

var c = fun(0).fun(1); c.fun(2); c.fun(3);
//undefined 0 1 1

5. 浅拷贝和深拷贝的区别,使用原生js写出一种深拷贝的方法

6. 6类型识别的方法

7. this的理解

 1 var length = 10;
 2 function fn() {
 3  console.log(this.length);
 4 }
 5 
 6 const  obj = {
 7     length: 5,
 8     method: function(fn) {
 9         fn();
10         arguments[0]();
11     }
12 };
13 
14 obj.method(fn, 1);

7. bind, call, apply的区别

8. 谈性能优化问题

Reference:

  1. 详说 Cookie, LocalStorage 与 SessionStorage https://jerryzou.com/posts/cookie-and-web-storage/
  2. Promise解释:https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/7
  3.  ES6 - let、const、var的区别 https://juejin.im/post/5c979586e51d4503626659c4
  4. 闭包的理解:https://juejin.im/
  5. this的理解:https://juejin.im/post/5a0d9ff4f265da432e5b91da
  6. JavaScript 的 this 原理:http://www.ruanyifeng.com/blog/2018/06/javascript-this.html
  7. 性能优化问题:https://juejin.im/post/5c46cbaee51d453f45612a2c
原文地址:https://www.cnblogs.com/JumperMan/p/12110875.html