Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript typeof Operator

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 272
    Comment on it

    The typeof Operator :

    typeof is a kind of keyword that returns a string which tells the data type of an expression.

    Syntax : `typeof operand`

    (The operand used is an expression representing the object or primitive whose type is to be returned.)

    The following example tests the data type of variables.

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>The typeof operator returns the type of a variable or an expression.</p>
    
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = 
    typeof "john" + "<br>" +  // Returns string 
    typeof 37 + "<br>" +       // Returns Number
    typeof 3.14 + "<br>" +    // Returns Number
    typeof true  + "<br>" +    // Returns Boolean
    typeof false + "<br>" +    // Returns Boolean
    typeof "" + "<br>" +         // Returns string
    typeof "bla" + "<br>" +     // Returns string
    typeof [1,2,3,4] + "<br>" + // Returns object 
    typeof {name:'john', age:34};  // Returns object
    </script>
    
    </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: