原始类型之typeof运算符
typeof
返回一个用来表示表达式的数据类型的字符串。
typeof[()expression[]] ;
expression 参数是需要查找类型信息的任意表 达式。
说明
typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 语法中的圆括号是可选项。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>原始类型之typeof运算符</title> <script type="text/javascript"> var s='s'; var i=12; var t=true; var nu=null; var undi; alert(typeof(s)+" "+typeof(i)+" "+typeof(t)+" "+typeof(nu)+" "+typeof(undi)); //output string number boolean object undefined </script> </head> <body> </body> </html>