一、JS闭包。
f
g
(function()
})();
alert(f());
------------------------
答案:
(function()
//应该看成if((g()
//因为g()是false后面那个&&[]就没起作用
//![]也是false
//重新定义f
//这句没用
})();
alert(f());
//false
二、截取字符串abcdefg的efg
三、写出一下运算结果
alert(typeof(null))
alert(typeof(undefined))
alert(typeof(NaN))
alert(NaN==undefined)
alert(NaN==NaN)
var str="123abc";
alert(typeof(str++)) // number
alert(str) // string
四、写出函数DateDemo的返回结果,系统时间假定为今天
function DateDemo(){
var d, s="今天日期是:";
d = new Date();
s += d.getMonth() + "/";
s += d.getDate() + "/";
s += d.getYear();
return s;
}
结果:今天日期是:7/17/2010
五、写出程序运行的结果?
for(i=0, j=0; i<10, j<6; i++, j++){
k = i + j;
}
结果:10(小心陷阱)
JS前端面试必备:面向对象,闭包以及匿名函数http://blog.sina.com.cn/s/articlelist_2113824731_7_1.html
更多JS面试题http://blog.sina.com.cn/s/articlelist_2113824731_8_1.html