js 面试题总结

来源:互联网 发布:外贸邮箱软件 编辑:程序博客网 时间:2024/06/05 06:39
1、(function(){return typeof arguments})();

  "object"

2、var f= function g(){return 11};console.log(typeof g());

  error

3、(function(x){delete x;return x;})(1);
  1
  delete只能删除对象的属性,删不掉变量和参数。

4、var y=1;x=y=typeof x ; console.log(x)
  undefined

  表达式从右向左执行

5、var a={b:function(){return this.b},c:1};

      (function(){

         return typeof arguments[0]();

  })(a.b);
  "undefined"

6、function a(){alert(this)};var b=[1,2,3];b.a=a;b.a();
  1,2,3
  函数中的this指向,不是函数本身,而是调用函数的地方

7、 var a={b:function(){return this.c;},c:1};typeof (f=a.b)();   

   本来a.b调用的时候指向a,但是a.b看成了一个整体f来调用,就导致调用函数没了指向,this便指向window,     window中是没有c这个对象的,所以undefined

8、var c=(function(){return 1;},function(){return 2;})(); console.log(c)
  2

  分类选择符,选择执行只执行最后一个

9、 var x=[typeof x,typeof y][1];typeof typeof x;
   string       

   typeof返回的是字符串,有六种,分别为:"number","string","boolean","object","function","undefined"

   eg:typeof typeof x;

   string

10、(function(b){return typeof b.a})({b:{a:1}});
   undefined

   函数执行时{b:{a:1}}作为了函数中的参数b,b没有属性a,所以b.a不存在

11、(function f(){ function f(){return 1;} return f();function f(){return 2;}})();  

   2
   函数声明预解析,后者将前者覆盖了,所以是2

12、

原创粉丝点击