Syntax
typeof(variable)
The typeof unary operator determines the type of the variable.
The return values are boolean, number, object, string, or undefined.
The following example uses the typeof Operator to Return the Types for Four Different Variables
<html> <head> <title>Using typeof to determine the type of variables</title> <script language="JavaScript1.1"> <!-- var bMyVar = true; var nMyVar = 35; var sMyVar = "This is a string"; var uMyVar; --> </script> </head> <body> <script language="JavaScript1.1"> <!-- document.writeln("bMyVar = " + typeof(bMyVar)); document.writeln("<br>nMyVar = " + typeof(nMyVar)); document.writeln("<br>sMyVar = " + typeof(sMyVar)); document.writeln("<br>uMyVar = " + typeof(uMyVar)); --> </script> </body> </html>