typeof Keyword

The typeof keyword is a operator that returns the string describing the type of operand .


The typeof operator is used in the following way:

typeof (operand )

The typeof operator returns a string indicating the type of the *unevaluated* operand. The operand is the string, variable, function identifier, or object for which the type is to be returned. When supplying identifier, it should be provided alone, without arithmetic operators, without extra arguments and without braces. If you want to check the type of value returned by the function, you must first assign the return value to a variable and then use:

typeof( variable )

Possible return values are:

if( typeof( somevar ) == "undefined" )
/// when somevar is undefined the code here will execute

The following sample COMMENTARY code shows the output of typeof() in some common situations:

x =
y =
LastValue( x );
function testfun() { return 1; };
printf( typeof( test ) + "\n" ); // the undefined variable
printf( typeof( 1 ) + "\n"); // literal number
printf( typeof( "checking" ) + "\n"); // literal string
printf( typeof( x ) + "\n"); // array variable
printf( typeof( y ) + "\n"); // scalar variable
printf( typeof( MACD ) + "\n"); // function identifier
printf( typeof( testfun ) + "\n" ); // user function identifier