typeof : typeof « Operators « JavaScript Tutorial






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>








2.13.typeof
2.13.1.The Typeof Operator
2.13.2.typeof
2.13.3.Get variable type
2.13.4.typeof a variable: number
2.13.5.typeof a variable: string