JavaScript 類型轉(zhuǎn)換
JavaScript?類型轉(zhuǎn)換
Number() 轉(zhuǎn)換為數(shù)字, String() 轉(zhuǎn)換為字符串, Boolean() 轉(zhuǎn)化為布爾值。
JavaScript 數(shù)據(jù)類型
在 JavaScript 中有 5 種不同的數(shù)據(jù)類型:
string
number
boolean
object
function
3 種對象類型:
Object
Date
Array
2 個(gè)不包含任何值的數(shù)據(jù)類型:
null
undefined
typeof 操作符
你可以使用?typeof?操作符來查看 JavaScript 變量的數(shù)據(jù)類型。
<html> <body> <script type="text/javascript"> var test=new Array(); if (test.constructor==Array) { document.write("This is an Array"); } if (test.constructor==Boolean) { document.write("This is a Boolean"); } if (test.constructor==Date) { document.write("This is a Date"); } if (test.constructor==String) { document.write("This is a String"); } </script> </body> </html>