OPERATOR:  typeof

typeof
 
The typeof operator is used to determine the type of a given expression. An integer is returned that defines the type.
 
There are five types recognized by WMLScript:
 
Type Integer
Integer 0
Floating-point 1
String 2
Boolean 3
Invalid 4

 
This example tests two expressions; the first is a floating-point number and the second is division by zero which is invalid.
 
Code for TypeofExample.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   typeof example
   </p>
   <do type="accept">
      <go href="TypeofExample.wmls#findtypeof()" />
   </do>
</card>

<card id="card2">
<p>
   1st expression = $(expression1)
   <br />
   1st type = $(typeinteger1)
   <br />
   2cd expression = $(expression2)
   <br />
   2cd type = $(typeinteger2)
</p>
</card>

</wml>

 
Code for TypeofExample.wmls
extern function findtypeof()
{
   var exp1 = 123.456;
   var int1 = typeof(exp1);
   WMLBrowser.setVar("expression1", exp1);
   WMLBrowser.setVar("typeinteger1", int1);
   var exp2 = 1/0;
   var int2 = typeof(exp2);
   WMLBrowser.setVar("expression2", exp2);
   WMLBrowser.setVar("typeinteger2", int2);
   WMLBrowser.go("TypeofExample.wml#card2");
};


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information