Distal pen questions 1 (pre-compiled, typeof, functions, arguments)

1. seeking x, y, z values
	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. Print out the function argument is 1,2,3,4,5 Yes.
//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. The results of the following expression is
parseInt(3,8);//3
parseInt(3,2);//NaN
parseInt(3,0);//3或者NaN或者报错
//parseInt()第二位参数是以后面的数字为基底,转换成10进制复制代码
4.javascript language typeof return results

string number boolean object undefined function

5. What results is a look at the following alert
 function b(x, y, z){
    arguments[2] = 10;
    alert(a);
}
b(1, 2, 3);
如果函数体改成下面,结果又会是什么?
a = 10;
alert(arguments[2]);
//映射关系复制代码
6. Write the result of the implementation of the following programs
var f =( 
    function f(){
        return '1';
    },
    function g(){
        return 2;
    }
)();
typeof f;//number
//*  , 逗号运算符返回第二个值复制代码
7. Which of the following expression evaluates to true
A.undefined == null;//true
B.undefined === null;
C.isNaN('100'); //true
D.parseInt('1a') == 1 //true复制代码
8. Write program executed following results
var foo = '123';
function print(){
    var foo = '456';
    this.foo = '789';
    console.log(foo);
    // console.log(this)-->window
}
print();复制代码
9. Write a program executed following results
var foo = 123;
function print(){
    this.foo = 234;//指向window
    console.log(foo);
}
//print();//234
//new print();//123复制代码

10. What operational test () and the new test () are the result of
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. Write the result of the implementation of the following programs
function print(){
    console.log(foo);//undefined
    var foo = 2;
    console.log(foo);//2
    console.log(hello);//报错 hello is not defined
}
print();复制代码
12. Write program executed following results
function print(){
    var test;
    test();
    function test(){
        console.log(1);
    }
}
print();//1复制代码
13. Write program executed following results
function print(){
    var x = 1;
    if(x == '1') console.log('One');
    if(x === '1') console.log('Two');
}
print();//One复制代码
14. Write program executed following results
 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. Write the following program execution
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复制代码


Reproduced in: https: //juejin.im/post/5d0715715188255fc63847fe

Guess you like

Origin blog.csdn.net/weixin_33682719/article/details/93177223