1. 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; Copy the code
2. Print the function whose arguments are 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);
returnx; } (1.2.3.4.5)
// No execution, but no error
/ / 3).
(function foo(x){
console.log(arguments);
returnx; } (1.2.3.4.5))
/ / 4).
function foo(){
bar.apply(null.arguments);
}
function bar(x){
console.log(arguments);
}
foo(1.2.3.4.5)Copy the code
3. The result of the following expression is
The parseInt (3, 8); / / 3 parseInt (3, 2); / / NaN parseInt (3, 0); //3 or NaN or an error //parseInt() the second argument is converted to base 10 for the following numberCopy the code
4. The result returned by javascript typeof
string number boolean object undefined function
5. What is the result of the following alert
function b(x, y, z){
arguments[2] = 10;
alert(a);
}
b(1.2.3); What would happen if the function style were changed to the following? a =10;
alert(arguments[2]);
// MappingCopy the code
6. Write down the results of the following procedures
var f =(
function f(){
return '1';
},
function g(){
return 2;
}
)();
typeof f;//number
The comma operator returns the second valueCopy the code
7. Which of the following expressions yields true
A.undefined == null; //true
B.undefined === null;
C.isNaN('100'); //true
D.parseInt('1a') = = 1 / /trueCopy the code
8. Write down the results of the following procedures
var foo = '123';
function print(){
var foo = '456';
this.foo = '789';
console.log(foo);
// console.log(this)-->window
}
print();Copy the code
9. Write down the results of the following procedures
var foo = 123;
function print(){
this.foo = 234;/ / points to the window
console.log(foo);
}
//print(); / / 234
//new print(); / / 123Copy the code
10. What is the result of running test() and 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 0Copy the code
11. Write down the results of the following procedures
function print(){
console.log(foo);//undefined
var foo = 2;
console.log(foo);/ / 2
console.log(hello);// Error hello is not defined
}
print();Copy the code
12. Write down the results of the following procedures
function print(){
var test;
test();
function test(){
console.log(1);
}
}
print();/ / 1Copy the code
13. Write down the results of the following procedures
function print(){
var x = 1;
if(x == '1') console.log('One');
if(x === '1') console.log('Two');
}
print();//OneCopy the code
14. Write down the results of the following procedures
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();Copy the code
15. Write the following program to execute
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,bCopy the code