前端笔试题1(预编译,typeof,函数,arguments)

1.求x,y,z值
var x = 1,y = z = 0;
	function add(n){
		return n = n + 1;
	}
	y = add(x);
	function add(n){
		return n = n + 3;
	}
	z = add(x);
	//x = 1,y = z = 4;	       复制代码
2.打印出实参是1,2,3,4,5的函数是。
//1).
function foo(x){
    console.log(arguments);
    return x;
}
foo(1,2,3,4,5)

//2).
function foo(x){
    console.log(arguments);
    return x;
}(1,2,3,4,5)
//不执行,可是不报错

//3).
(function foo(x){
    console.log(arguments);
    return x;
}(1,2,3,4,5))

//4).
function foo(){
    bar.apply(null,arguments);
}
function bar(x){
    console.log(arguments);
}
foo(1,2,3,4,5)复制代码
3.如下表达式的结果是
parseInt(3,8);//3
parseInt(3,2);//NaN
parseInt(3,0);//3或者NaN或者报错
//parseInt()第二位参数是之后面的数字为基底,转换成10进制复制代码
4.javascript语言typeof返回的结果

string number boolean object undefined functionjavascript

5.看看下面alert的结果是什么
function b(x, y, z){
    arguments[2] = 10;
    alert(a);
}
b(1, 2, 3);
若是函数体改为下面,结果又会是什么?
a = 10;
alert(arguments[2]);
//映射关系复制代码
6.写出下列程序执行的结果
var f =( 
    function f(){
        return '1';
    },
    function g(){
        return 2;
    }
)();
typeof f;//number
//* , 逗号运算符返回第二个值复制代码
7.如下哪些表达式的结果为true
A.undefined == null;//true
B.undefined === null;
C.isNaN('100'); //true
D.parseInt('1a') == 1 //true复制代码
8.写出下列程序执行的结果
var foo = '123';
function print(){
    var foo = '456';
    this.foo = '789';
    console.log(foo);
    // console.log(this)-->window
}
print();复制代码
9.写出下列程序执行的结果
var foo = 123;
function print(){
    this.foo = 234;//指向window
    console.log(foo);
}
//print();//234
//new print();//123复制代码

10. 运行test() 和 new test()的结果分别是什么
var a = 5;
function test(){
    a = 0;
    alert(a);
    alert(this.a);
    var a;
    alert(a);
}
// test();//0 5 0
new test();//0 undefined 0复制代码
11.写出下列程序执行的结果
function print(){
    console.log(foo);//undefined
    var foo = 2;
    console.log(foo);//2
    console.log(hello);//报错 hello is not defined
}
print();复制代码
12.写出下列程序执行的结果
function print(){
    var test;
    test();
    function test(){
        console.log(1);
    }
}
print();//1复制代码
13.写出下列程序执行的结果
function print(){
    var x = 1;
    if(x == '1') console.log('One');
    if(x === '1') console.log('Two');
}
print();//One复制代码
14.写出下列程序执行的结果
function print(){
    var marty = {
        name:'marty',
        printName:function(){
            console.log(this.name);//marty
        }
    }
    var test1 = {name:'test1'};
    var test2 = {name:'test2'};
    var test3 = {name:'test3'};
    test3.printName = marty.printName;
    // var printName2 = marty.printName.bind({name:123});
    marty.printName.call(test1);//test1
    marty.printName.apply(test2);//test2
    marty.printName();//marty
    // printName2();//
    test3.printName();//test3
}
print();复制代码
15.写出下列程序执行的
var bar = {a:'002'};
function print(){
    bar.a = 'a';
    Object.prototype.b = 'b';
    return function inner(){
        console.log(bar.a);
        console.log(bar.b);
    }
}
print()();//a,b复制代码
相关文章
相关标签/搜索