js面试题(4)

1.下面在控制台打印什么?

console.log(typeof null , null instanceof Object) //object false

2.下面在控制台打印什么?

console.log( []["map"]+[1,2] )  //"function map() { [native code] }1,2"
[]['a']+[1,[2,3],4]  //"undefined1,2,3,4"
[]['push'](1,3) //2  返回push后数组的长度
[1,3]['pop']()  //3  返回删除的项 (pop从数组末尾删除一条数据)

(![]+[])[+[]]   //"f"
// ![]=false    []=''   +[]=0    +''=0

(![]+[])[!![]]  //undefined
//(![]+[])='false'

''+{}	//[object object]

1<2<3 //true
//1<2=true=1; 0<3=true
3<2<1 //true
//3<2=false=0; 0<1=true
++[[]][+[]] + [+[]]  //"10"

∵ [[]][0] = []; var a = []; ++a=1;
∴ ++[[]][+[]] = 1;

3.阅读下面代码,输出是什么?

var a = 1;
function add(n){
	return n=n+3;
}
y = add(a);
function add(n){
	return n=n*5;
}
z = add(a);
console.log(y,z);	//5 5

4.阅读下面代码,输出是什么?

function showCase(value){
  switch(value){
    case 'A':
       console.log('Case A');
       break;
    case 'B':
       console.log('Case B');
       break;
    case 'undefind':
       console.log('undefind');
       break;
    case new String('A'):
       console.log(new String('A'));
       break;
    default:
       console.log('Do not know!');
       break;
  }
}
showCase(new String('A')); //'Do not know!'
//new String('A')是字符串对象 对象地址相同才相等
//switch内需要满足===

5.阅读下面代码,输出是什么?

parseInt(3,8)	//3
parseInt(3,2)	//NaN
parseInt(3,0)	//3   y=0表示是10进制的数字
parseInt(x,y)	//把y进制的x转换成10进制的数字 y:[2~36]

6.阅读下面代码,输出是什么?

[1,2,3].map(function(value,index){
  return value*2
})
//[2, 4, 6]

['1','2','3'].map(parseInt)  //[1,NaN,NaN]
// [parseInt('1',0), parseInt('2',1), parseInt('3',2)]

7.阅读下面代码,输出是什么?

function fn(ary){
  ary[0] = ary[2];
}
function bar(a,b,c){
  c = 10;
  fn(arguments); 
  return a + b + c;
}
bar(1,1,1);  //21

8.以下面代码,输出是什么?

console.log(Array.isArray(Array.prototype)) // true
function fn(){}
console.log(Object.getPrototypeOf(fn)) // ƒ () { [native code] }
//数组的原型是数组 函数的原型是函数  (getPrototypeOf获取原型)

9.以下面代码,输出是什么?

(function(){
  var x = y = 1;
})();
console.log(y); // 1
console.log(x);	//ReferenceError: x is not defined

10.以下面代码,输出是什么?

if(typeof c && -true + (+undefined)+''){  //
   console.log('1 am ok');
}
//typeof c = 'undefined'   -1 +NaN +'' = "NaN"

if(22+'33'*2 == 88){ 	//true
   console.log('我还能做10道');
}

!!' ' +  !!'' - !!false||console.log('我选择go die'); //1
//!!' ' +  !!'' - !!fasle=1

11.以下面代码,输出是什么?

var length = 10
function fn(){
   console.log(this.length);
}
var obj = {
  length:5,
  method:function(){
    console.log(this.length); //5
    fn();  //10   //this指向window
    arguments[0](); //2  //this指向arguments
  },
  fn:fn
}
obj.method(fn,1)
obj.fn() //5

12.以下面代码,输出是什么?

var a={},
b={key:'b'},
c={key:'c'};

a[b]=123; //a[object object]=123
a[c]=456; //a[object object]=123
console.log(a[b]); //456
发布了218 篇原创文章 · 获赞 35 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_41614928/article/details/102513439