WEB2.0 web20
当前位置:首页 > 网站建设专题 > WEB2.0
JavaScript基础知识篇-你真的了解JavaScript吗?
发布日期:2009-08-24 阅读次数:5253 字体大小:

你真的了解JavaScript吗?

让我们重温一下JavaScript的一些基础知识,请先写出以下代码中问号处的答案,再运行比较!

<script type="text/javascript">

var a=0,b=0,c=0;
a+++b+++c;
alert(a,b,c);//?

var a=;
alert(aa++);//?
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