typeof 演算子

式のデータ型を識別する文字列を返します。

typeof[(]expression[)] ;

引数

  • expression
    必ず指定します。 任意の式を指定します。

解説

typeof 演算子は、型情報を文字列で返します。 typeof 演算子が返す文字列は、"number"、"string"、"boolean"、"object"、"function"、"date"、"undefined"、"unknown" の 8 つです。

typeof の構文のかっこは省略できます。

注意

JScript のすべての式で、GetType メソッドを使用できます。 このメソッドは、式のデータ型を返します (データ型を表す文字列ではありません)。 typeof 演算子よりも、GetType メソッドの方がより詳細な情報を得られます。

使用例

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

必要条件

Version 1

参照

参照

GetType

概念

演算子の優先順位

演算子の一覧