一定要先自己计算,完成后在测试答案,不要直接的输出看答案,这样就没有意义了
一
1、
console.log(a);
var a=12;
function fn(){
console.log(a);
var a=13;
}
fn();
console.log(a);
/*
A、undefined 12 13
B、undefined undefined 12
C、undefined undefined 13
D、有程序报错
*/
2、
console.log(a);
var a=12;
function fn(){
console.log(a);
a=13;
}
fn();
console.log(a);
/*
A、undefined 12 13
B、undefined undefined 12
C、undefined undefined 13
D、有程序报错
*/
3、
console.log(a);
a=12;
function fn(){
console.log(a);
a=13;
}
fn();
console.log(a);
/*
A、undefined 12 13
B、undefined undefined 12
C、undefined undefined 13
D、有程序报错
*/
4、
var foo=1;
function bar(){
if(!foo){
var foo=10;
}
console.log(foo);
}
bar();
/*
A、1
B、10
C、undefined
D、报错
*/
5、
var n=0;
function a(){
var n=10;
function b(){
n++;
console.log(n);
}
b();
return b;
}
var c=a();
c();
console.log(n);
/*
A、1 1 1
B、11 11 0
C、11 12 0
D、11 12 12
*/
6、
var a=10,b=11,c=12;
function test(a){
a=1;
var b=2;
c=3;
}
test(10);
console.log(a);
console.log(b);
console.log(c);
/*
A、1 11 3
B、10 11 12
C、1 2 3
D、10 11 3
*/
7、
if(!("a" in window)){
var a=1;
}
console.log(a);
/*
A、1
B、undefined
C、报错
D、以上答案都不对
*/
8、
var a=4;
function b(x,y,a) {
console.log(a);
arguments[2]=10;
console.log(a);
}
a=b(1,2,3);
console.log(a);
/*
A、3 3 4
B、3 10 4
C、3 10 10
D、3 10 undefined
*/
9、
var foo='hello';
(function(foo){
console.log(foo);
var foo=foo||'world';
console.log(foo);
})(foo);
console.log(foo);
/*
A、hello hello hello
B、undefined world hello
C、hello world world
D、以上答案都不正确
*/
10、
var a=9;
function fn(){
a=0;
return function(b){
return b+a++;
}
}
var f=fn();
console.log(f(5));
console.log(fn()(5));
console.log(f(5));
console.log(a);
/*
A、6 6 7 2
B、5 6 7 3
C、5 5 6 3
D、以上答案都不正确
*/
二
1、
var ary=[1,2,3,4];
function fn(ary){
ary[0]=0;
ary=[0];
ary[0]=100;
return ary;
}
var res=fn(ary);
console.log(ary);
console.log(res);
2、
function fn(i) {
return function (n) {
console.log(n + (i++));
}
}
var f = fn(10);
f(20);
fn(20)(40);
fn(30)(50);
f(30);
3、
var i = 10;
function fn() {
return function (n) {
console.log(n + (++i));
}
}
var f = fn();
f(20);
fn()(20);
fn()(30);
f(30);
4、
var test = (function(i){
return function(){
alert(i*=2);
}
})(2);
test(5);
5、
var a=1;
var obj ={
"name":"tom"
}
function fn(){
var a2 = a;
obj2 = obj;
a2 =a;
obj2.name =”jack”;
}
fn();
console.log(a);
console.log(obj);
6、
var a = 1;
function fn(a){
console.log(a)
var a = 2;
function a(){}
}
fn(a)
7、
var a=0,
b=0;
function A(a){
A=function(b){
alert(a+b++);
};
alert(a++);
}
A(1);
A(2);
三
var num = 10;
var obj = {num: 20};
obj.fn = (function (num) {
this.num = num * 3;
num++;
return function (n) {
this.num += n;
num++;
console.log(num);
}
})(obj.num);
var fn = obj.fn;
fn(5);
obj.fn(10);
console.log(num, obj.num);
var fullName='language';
var obj={
fullName:'javascript',
prop:{
getFullName:function(){
return this.fullName;
}
}
};
console.log(obj.prop.getFullName());
var test=obj.prop.getFullName;
console.log(test());
var name='window';
var Tom={
name:"Tom",
show:function(){
console.log(this.name);
},
wait:function(){
var fun=this.show;
fun();
}
};
Tom.wait();
function fun(){
this.a=0;
this.b=function(){
alert(this.a);
}
}
fun.prototype={
b:function(){
this.a=20;
alert(this.a);
},
c:function(){
this.a=30;
alert(this.a)
}
}
var my_fun=new fun();
my_fun.b();
my_fun.c();
window.val=1;
var json={
val:10,
dbl:function(){
this.val*=2;
}
}
json.dbl();
var dbl = json.dbl;
dbl();
json.dbl.call(window);
alert(window.val + json.val);
(function(){
var val =1;
var json ={
val:10,
dbl:function(){
val*=2;
}
};
json.dbl();
alert(json.val+val);
})();
function C1(name){
if(name) {
this.name = name;
}
}
function C2(name){
this.name =name;
}
function C3(name){
this.name = name ||'join';
}
C1.prototype.name='Tom';
C2.prototype.name='Tom';
C3.prototype.name='Tom';
alert((new C1().name)+(new C2().name)+(new C3().name));
var foo = {
bar: function () {
console.log(this);
}
};
foo.bar();
(foo.bar)();