Returns a string that identifies the data type of an expression.
- Required. Any expression.
The typeof operator returns type information as a string. There are six possible values that typeof returns: "number", "string", "boolean", "object", "function", and "undefined".
The parentheses are optional in the typeof syntax.
Note : All expressions in JScript .NET 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.
The following example illustrates the use of the typeof operator.
var x : double = Math.PI; var y : String = "Hello"; var z : int = new int; 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