How To Use typeof Operator Using JavaScript?


Share:
Published By: Admin, Published On: Nov 20, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to use typeof operator example. We will check use of typeof operator using javascript. This is a short guide on use typeof operator in javascript. Let's get started with how to use typeof operator in javascript.

Here i will give you many example how to use typeof operator using javascript.

Example : 1
<html>
    <head>
        <title>How To Use typeof Operator Using JavaScript? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use typeof Operator Using JavaScript? - MyWebtuts.com</h3>
        <script>
            document.write(typeof (8) + "<br>");  
            document.write(typeof (3) + "<br>");  
            document.write(typeof ("MyWebtuts.com") + "<br>");
            document.write(typeof (true) + "<br>");  
            document.write(typeof (Infinity) + "<br>");
        </script>
    </body>
</html>  
Output :
number
number
string
boolean
number
Example : 2
<html>
    <head>
        <title>How To Use typeof Operator Using JavaScript? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use typeof Operator Using JavaScript? - MyWebtuts.com</h3>
        <script>
            document.write(typeof null + "<br>");
            document.write(typeof [8, 3, 'abc'] + "<br>");
            document.write(typeof {x: 'xyz'} + "<br>");
            document.write(typeof n + "<br>");
            document.write(typeof function(){} + "<br>");
            document.write(typeof class abc{} + "<br>");
        </script>
    </body>
</html>  
Output :
object
object
object
undefined
function
function

It will help you...

Share: