標籤:type blog href log xmlns head tag body asc
javascript的資料類型:NumberStringBooleanundefined 共4種。
類型的總結:所有的數值都是number類型字元和字串都是string類型布爾是boolean類型如果一個變數沒有初始化值的時候,其類型為undefined類型。表示沒有定義。
typeof 可以查看變數的資料類型。使用格式:typeof 變數名 或者 typeof(變數名)
案例代碼:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>javascript資料類型</title><script type="text/javascript">/*javascript的資料類型:numberstringbooleanundefined 共4種。類型的總結:所有的數值都是number類型字元和字串都是string類型布爾是boolean類型如果一個變數沒有初始化值的時候,其類型為undefined類型。表示沒有定義。typeof可以查看變數的資料類型。使用格式:typeof 變數名*/document.write("10資料類型是:" + (typeof 10) + "<br/>");document.write("9.99資料類型是:" + (typeof 9.99) + "<br/>");document.write("‘a‘資料類型是:" + (typeof ‘a‘) + "<br/>");document.write("‘abc‘資料類型是:" + (typeof ‘abc‘) + "<br/>");document.write("\"abcdef\"資料類型是:" + (typeof "abcdef") + "<br/>");document.write("true資料類型是:" + (typeof true) + "<br/>");document.write("a資料類型是:" + (typeof a) + "<br/>");</script></head><body></body></html>
結果如下:
來自為知筆記(Wiz)
資料類型【js】