前端筆試題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複製代碼
相關文章
相關標籤/搜索