Returns a string that identifies the data type of an expression.
typeof[(]expression[)] ; |
Arguments
- expression
-
Required. Any expression.
Remarks
The typeof operator returns type information as a string. There are eight possible values that typeof returns: "number", "string", "boolean", "object", "function", "date", "undefined" and "unknown".
The parentheses are optional in the typeof syntax.
![]() |
---|
: All expressions in JScript have a GetType method. This method returns the data type (not a string representing the data type) of the expression. The GetType method provides more information than the typeof operator. |
Example
The following example illustrates the use of the typeof operator.
В | ![]() |
---|---|
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 output of this code is:
The type of x (a double) is number
The type of y (a String) is string
The type of z (an int[]) is object
Requirements
See Also
