javascript typeof的用法與typeof運算符介紹[詳細]第1/2頁
更新時間:2008年10月31日 23:10:50 作者:
下面是對于typeof運算符的詳細介紹跟typeof的一些用法,分析,學(xué)習(xí)typeof的朋友,看完了,這篇應(yīng)該能有所收獲。
經(jīng)常會在js里用到數(shù)組,比如 多個名字相同的input, 若是動態(tài)生成的, 提交時就需要判斷其是否是數(shù)組.
if(document.mylist.length != "undefined" ) {} 這個用法有誤.
正確的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的運算數(shù)未定義,返回的就是 "undefined".
運算數(shù)為數(shù)字 typeof(x) = "number"
字符串 typeof(x) = "string"
布爾值 typeof(x) = "boolean"
對象,數(shù)組和null typeof(x) = "object"
函數(shù) typeof(x) = "function"
typeof 運算符返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 運算符
返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
typeof[()expression[]] ;
expression 參數(shù)是需要查找類型信息的任意表達式。
說明
typeof 運算符把類型信息當(dāng)作字符串返回。typeof 返回值有六種可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 語法中的圓括號是可選項。
if(document.mylist.length != "undefined" ) {} 這個用法有誤.
正確的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的運算數(shù)未定義,返回的就是 "undefined".
運算數(shù)為數(shù)字 typeof(x) = "number"
字符串 typeof(x) = "string"
布爾值 typeof(x) = "boolean"
對象,數(shù)組和null typeof(x) = "object"
函數(shù) typeof(x) = "function"
typeof 運算符返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 運算符
返回一個用來表示表達式的數(shù)據(jù)類型的字符串。
typeof[()expression[]] ;
expression 參數(shù)是需要查找類型信息的任意表達式。
說明
typeof 運算符把類型信息當(dāng)作字符串返回。typeof 返回值有六種可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 語法中的圓括號是可選項。
相關(guān)文章
如何利用JavaScript讀取excel文件并繪制echarts圖形
這篇文章主要介紹了如何利用JavaScript讀取excel文件并繪制echarts圖形,文章通過excel財務(wù)報表,并且需要根據(jù)這張excel表繪制成各種echarts圖形,需要了解更多詳情的小伙伴可以參考一下文章內(nèi)內(nèi)容2022-05-05JavaScript簡單判斷復(fù)選框是否選中及取出值的方法
這篇文章主要介紹了JavaScript簡單判斷復(fù)選框是否選中及取出值的方法,涉及javascript遍歷復(fù)選框及元素取值的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08JavaScript中調(diào)用函數(shù)的4種方式代碼實例
這篇文章主要介紹了JavaScript中調(diào)用函數(shù)的4種方式代碼實例,本文分別給出方法調(diào)用模式、函數(shù)調(diào)用模式、構(gòu)造器調(diào)用模式、apply調(diào)用模式4種方式的代碼實例,需要的朋友可以參考下2015-07-07