Example

typeof operator

HTML

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <link name="favicon" type="image/x-icon" href="https://skillzam.com/uploads/system/e353194f3b7cd1b75d69c3ab88041985.png" rel="shortcut icon" />
    <title>typeof operator</title>
</head>  
<body>
<!--
    typeof : operator is used to check which datatype is stored in a variable.
             Syntax : typeof x
                      typeof(x)        
-->

    <h1>Demo: typeof() Operator </h1>

    <p id="para"></p>
    
    <!-- JavaScript code Starts here -->
    <script>

        /************************************************/
        // typeof operator Example 
        //
        const num = 34;
        let text = "Workzam";
        let largeInteger = 10n;
        let isGreater = true;
        let anyValue = null;    // typeof() returns object type for null
        let name;

        document.getElementById("para").innerHTML =
        "typeof(num) = " + typeof(num) + "<BR>" +
        "typeof(NaN) = " + typeof(NaN) + "<BR>" +
        "typeof(text) = " + typeof(text) + "<BR>" +
        "typeof(largeInteger) = " + typeof(largeInteger)  + "<BR>" +
        "typeof(isGreater) = " + typeof(isGreater) + "<BR>" +   
        "typeof(anyValue) = " + typeof(anyValue) + "<BR>" +   
        "typeof(name) = " + typeof(name);

    </script>
    <!-- JavaScript code Ends here -->

</body>
</html>                    

Output

View original