返回一个用于标识表达式的数据类型的字符串。
typeof[(]expression[)] ;
- 表达式
必选。任何表达式。
typeof 运算符把类型信息以字符串形式返回。typeof 返回八种可能的值:“数字类型”、“字符串类型”、“布尔型”、“对象类型”、“函数类型”、“日期类型”、“未定义类型”和“未知类型”。
typeof 语法中的圆括号是可选的。
![]() |
---|
:JScript 中的所有表达式都有一个 GetType 方法。该方法返回表达式的数据类型(而不是表示数据类型的字符串)。GetType 方法比 typeof 运算符提供更多信息。 |
下面的示例阐释 typeof 运算符的用法。
var x : double = Math.PI; var y : String = "Hello"; var z : int[] = new int[10]; print("The type of x (a double) is " + typeof(x) ); print("The type of y (a String) is " + typeof(y) ); print("The type of z (an int[]) is " + typeof(z) );
该代码的输出为:
The type of x (a double) is number
The type of y (a String) is string
The type of z (an int[]) is object
要求请参见参考
GetType概念
运算符优先级运算符摘要