Sidebar

How can I determine the type of my variable?

0 votes
510 views
asked Jul 5, 2013 by mike-r-7535 (13,830 points)
edited Jul 8, 2013 by mike-r-7535
How do I know if I have a Java String, a Javascript String, or some other Java object?

1 Answer

+1 vote
 
Best answer

Use the Javascript typeof key word to determine what kind of javascript object.  If it is a Java object, then you can use the getClass() or instanceof key word method to determine what type of Java object.

// Assume myVar is already assigned a value

var myType = typeof myVar;

if (myType === "object") {

   myType = myVar.getClass();

}

qie.debug("The type of myVar is: " + myType);

answered Jul 5, 2013 by mike-r-7535 (13,830 points)
edited Jul 10, 2013 by mike-r-7535
commented Jul 10, 2013 by rich-c-2789 (16,240 points)
Are the variable names correct in the example?  I think someVar should say myVar and myVar in the body of the if should be myType.
commented Jul 10, 2013 by mike-r-7535 (13,830 points)
Thanks.  I corrected the variable names.
...