最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript typeof的用法與typeof運算符介紹[詳細(xì)]第2/2頁

 更新時間:2008年10月31日 23:10:50   作者:  
下面是對于typeof運算符的詳細(xì)介紹跟typeof的一些用法,分析,學(xué)習(xí)typeof的朋友,看完了,這篇應(yīng)該能有所收獲。

typeof運算符介紹:
typeof 是一個一元運算,放在一個運算數(shù)之前,運算數(shù)可以是任意類型。
它返回值是一個字符串,該字符串說明運算數(shù)的類型。
你知道下面typeof運算的結(jié)果嗎?
typeof(1);
typeof(NaN);
typeof(Number.MIN_VALUE);
typeof(Infinity);
typeof("123");
typeof(true);
typeof(window);
typeof(document);
typeof(null);
typeof(eval);
typeof(Date);
typeof(sss);
typeof(undefined);
看看你會幾個?

如果看了以后,不是很明白的話,請看下面(明白的人就不用往下看了):
typeof是一個一元運算符,它返回的結(jié)果始終是一個字符串,對不同的操作數(shù),它返回不同的結(jié)果。
具體的規(guī)則如下:
一、對于數(shù)字類型的操作數(shù)而言, typeof 返回的值是 number。比如說:typeof(1),返回的值就是number。
上面是舉的常規(guī)數(shù)字,對于非常規(guī)的數(shù)字類型而言,其結(jié)果返回的也是number。比如typeof(NaN),NaN在
JavaScript中代表的是特殊非數(shù)字值,雖然它本身是一個數(shù)字類型。
在JavaScript中,特殊的數(shù)字類型還有幾種:
Infinity 表示無窮大特殊值
NaN            特殊的非數(shù)字值
Number.MAX_VALUE     可表示的最大數(shù)字
Number.MIN_VALUE     可表示的最小數(shù)字(與零最接近)
Number.NaN        特殊的非數(shù)字值
Number.POSITIVE_INFINITY 表示正無窮大的特殊值
Number.NEGATIVE_INFINITY 表示負(fù)無窮大的特殊值
以上特殊類型,在用typeof進(jìn)行運算進(jìn),其結(jié)果都將是number。
二、對于字符串類型, typeof 返回的值是 string。比如typeof("123")返回的值是string。
三、對于布爾類型, typeof 返回的值是 boolean 。比如typeof(true)返回的值是boolean。
四、對于對象、數(shù)組、null 返回的值是 object 。比如typeof(window),typeof(document),typeof(null)返回的值都是object。
五、對于函數(shù)類型,返回的值是 function。比如:typeof(eval),typeof(Date)返回的值都是function。
六、如果運算數(shù)是沒有定義的(比如說不存在的變量、函數(shù)或者undefined),將返回undefined。比如:typeof(sss)、typeof(undefined)都返回undefined。
<style>
body{font-size:20px;color:#222222;font-family:宋體;line-height:22px;}
</style>
<script>
document.write ("typeof(1): "+typeof(1)+"<br>");
document.write ("typeof(NaN): "+typeof(NaN)+"<br>");
document.write ("typeof(Number.MIN_VALUE): "+typeof(Number.MIN_VALUE)+"<br>")
document.write ("typeof(Infinity): "+typeof(Infinity)+"<br>")
document.write ("typeof(\"123\"): "+typeof("123")+"<br>")
document.write ("typeof(true): "+typeof(true)+"<br>")
document.write ("typeof(window): "+typeof(window)+"<br>")
document.write ("typeof(document): "+typeof(document)+"<br>")
document.write ("typeof(null): "+typeof(null)+"<br>")
document.write ("typeof(eval): "+typeof(eval)+"<br>")
document.write ("typeof(Date): "+typeof(Date)+"<br>")
document.write ("typeof(sss): "+typeof(sss)+"<br>")
document.write ("typeof(undefined): "+typeof(undefined)+"<br>")
</script>

相關(guān)文章

最新評論

大埔县| 海晏县| 永丰县| 勃利县| 彭山县| 崇义县| 保康县| 蒲江县| 靖边县| 微博| 蒙自县| 晋宁县| 嘉荫县| 庆元县| 从江县| 乐山市| 怀来县| 石城县| 尉犁县| 禄丰县| 册亨县| 喀什市| 永济市| 泗阳县| 大关县| 南宁市| 怀集县| 娄烦县| 深圳市| 襄城县| 华池县| 方山县| 阿瓦提县| 乌什县| 禹州市| 淮滨县| 澄江县| 大关县| 安图县| 镇沅| 阿坝|