位置: 首页 / 技术文档 / JavaScript技术
你真的了解JavaScript吗?
让我们重温一下JavaScript的一些基础知识,请先写出以下代码中问号处的答案,再运行比较!
<script type="text/JavaScript">
var a=0,b=0,c=0;
a+++b+++c;
alert([a,b,c]);//?
var a=[];
alert(a[a++]);//?
alert(a);//?
var o={a:o++};
alert(o.a);//?
var f=function(){};
alert(f(f++));
alert(typeof(NaN))//?
alert(typeof(Infinity))//?
alert(typeof(null))//?
alert(typeof(undefined))//?
alert(NaN == NaN)//?
alert(NaN != NaN)//?
alert(NaN >= NaN)//?
alert(null == undefined)//?
alert(null >= undefined)//?
alert(null <= undefined)//?
alert(parseInt("123abc"))//?
alert(("123abc" - 0))//?
alert(Infinity > 10)//?
alert(Infinity > "abc")//?
alert(Infinity == NaN)//?
alert(true == 1)//?
alert(new String("abc") == "abc")//?
alert(new String("abc") === "abc")//?
var a = "123abc";
alert(typeof(a++));//?
alert(a);//?
var a = "123abc";
a.valueOf = function(){return parseInt(a);}
alert(++a);//?
alert(a-0);//?
var a = new Object();
a.toString = function(){return "123abc";}
a.valueOf = function(){return parseInt(a);}
alert(++a);//?
alert(a-0);//?
var spv = String.prototype.valueOf;
String.prototype.valueOf = function(){
return parseFloat(this);
}
alert("123abc" > 122);//?
alert(new String("123abc") > 122);//?
String.prototype.valueOf = spv;
var s = new String("abc");
alert(typeof(s) == typeof("abc"));//?
alert(s === "abc");//?
alert(s.toString() == s);//?
var a = new Object(),b = new Object();
a.toString = function(){return "a"};
b.toString = function(){return "b"};
alert(a>b);//?
a.valueOf = function(){return 1};
b.valueOf = function(){return 0};
alert(a>b);//?
var step = function(a){
return function(x){
return x + a++;
}
}
var a = step(10);
var b = step(20);
alert(a(10));//?
alert(b(10));//?
</script>
运行代码查看结果:http://www.jslab.org.cn/?tag=JavaScriptBasis
希望大家在学习JavaScript的时候注意基本功的练习!
原文地址:http://www.v-ec.com/dh20156/article.asp?id=264
类别:JavaScript技术 来源:本站原创 作者:hpping 日期:2009-08-24 14:53
上一条:基于EasyUI的全站表单AJAX提交验证及返回值提示功能的实现
下一条:对现代开发来说,JavaScript是一种垃圾语言